設定 詢問 /dev/net/tun的裝置特性

來源:互聯網
上載者:User

#include <linux/if_tun.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <stdio.h>

static struct {
unsigned int flag;
const char *name;
} known_flags[] = {
{ IFF_TUN, "TUN" },
{ IFF_TAP, "TAP" },
{ IFF_NO_PI, "NO_PI" },
{ IFF_ONE_QUEUE, "ONE_QUEUE" },
};

int main()
{
    unsigned int features, i;
    
    int netfd = open("/dev/net/tun", O_RDWR);
    if (netfd < 0)
        err(1, "Opening /dev/net/tun");
    
    printf("%x\n", TUNGETFEATURES);
    
    if (ioctl(netfd, TUNGETFEATURES, &features) != 0) {
        printf("Kernel does not support TUNGETFEATURES, guessing\n");
        features = (IFF_TUN|IFF_TAP|IFF_NO_PI|IFF_ONE_QUEUE);
    }
    printf("Available features are: ");
    for (i = 0; i < sizeof(known_flags)/sizeof(known_flags[0]); i++) {
        if (features & known_flags[i].flag) {
            features &= ~known_flags[i].flag;
            printf("%s ", known_flags[i].name);
        }
        }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.