linux - 为什么我会收到 "implicit declaration of function ' ndo_get_stats“错误?

标签 linux device-driver kernel-module

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

#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_stats 是一个 net_device_ops 函数指针。您必须通过 net_devicenetdev_ops 字段调用它。

像这样的东西会起作用:

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

关于linux - 为什么我会收到 "implicit declaration of function ' ndo_get_stats“错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10084964/

相关文章:

c - 如何用 fork 和 mkfifo 制作一个进程环?

java - 检查用户是否是 java 应用程序中的 root

linux - Fedora:右键单击鼠标执行命令

linux - 处理来自 LPC 连接设备的 SERIRQ 中断

linux - 如何从内核模块使用 XPS(传输数据包控制)

linux - 为 Linux 命令中的参数提供空值

c - 将枚举从内核模块传递到用户空间程序

linux - 在软件中断期间cpu是否切换到中断上下文?

linux - 构建内核模块时如何链接静态库?

linux - 使用 dd 转储映射缓冲区