Getting list of network devices inside the Linux kernel

前端 未结 2 414
耶瑟儿~
耶瑟儿~ 2021-02-01 23:10

I\'ve been looking through net/core/dev.c and other files to try to find out how to get the list of network devices that are currently configured and it\'s proving to be a littl

2条回答
  •  礼貌的吻别
    2021-02-01 23:54

    This ought to do the trick:

    #include 
    
    struct net_device *dev;
    
    read_lock(&dev_base_lock);
    
    dev = first_net_device(&init_net);
    while (dev) {
        printk(KERN_INFO "found [%s]\n", dev->name);
        dev = next_net_device(dev);
    }
    
    read_unlock(&dev_base_lock);
    

提交回复
热议问题