为什么我会收到“函数'ndo_get_stats'的隐式声明"错误? [英] why am I getting an "implicit declaration of function 'ndo_get_stats' " error?

查看:146
本文介绍了为什么我会收到“函数'ndo_get_stats'的隐式声明"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个非常简单的内核模块,用于从网卡收集一些统计信息,这是代码,我一直收到错误implicit declaration of function 'ndo_get_stats'.我不确定为什么...

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);

谢谢

推荐答案

ndo_get_statsnet_device_ops函数指针.您必须通过net_devicenetdev_ops字段来调用它.

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

类似的事情会起作用:

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

这篇关于为什么我会收到“函数'ndo_get_stats'的隐式声明"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆