why am I getting an “implicit declaration of function 'ndo_get_stats' ” error?

我的未来我决定 提交于 2019-12-08 05:13:14

问题


I'm building a VERY SIMPLE kernel module for gathering some stats from the network card here's the code, I keep getting an error implicit declaration of function 'ndo_get_stats'. I'm not sure why...

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/netdevice.h>    /* Needed for netdevice*/



static int __init hello_start(void)
{
    struct net_device *dev;



    printk(KERN_INFO "Loading Stats module...\n");
    printk(KERN_ALERT "Hello world\n");
    dev = first_net_device(&init_net);
    while (dev)
    {
         printk(KERN_INFO "found [%s] and it's [%d]\n", dev->name, dev->flags & IFF_UP);

         printk(KERN_INFO "End of dev struct ... now starts the get_stats struct\n");

     dev->stats = ndo_get_stats(dev);

     printk(KERN_INFO "recive errors: [%li]\n transmission errors: [%li]\n number of collisions: [%li]", dev->stats.rx_errors , dev->stats.tx_errors, dev->stats.collisions);

      dev = next_net_device(dev);
     }

    return 0;
}

static void __exit hello_end(void)
{
    printk(KERN_ALERT "Goodbye.\n");
}

module_init(hello_start);
module_exit(hello_end);

Thanks


回答1:


ndo_get_stats is a net_device_ops function pointer. You have to call it through the netdev_ops field of your net_device.

Something like this would work:

stats = dev->netdev_ops->ndo_get_stats(dev);


来源:https://stackoverflow.com/questions/10084964/why-am-i-getting-an-implicit-declaration-of-function-ndo-get-stats-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!