qq_20738807 2016-12-14 14:25 采纳率: 0%
浏览 1517

Linux 下学习hook函数使用时用GCC编译报错

使用linux下netfilter和hook函数,使用结构体nf_hook_ops定义时总是报错 invalid use of undefined type ‘struct nf_hook_ops’,我已经在添加了该有的头文件,代码和网上很多一样,就是简单的netfilter hook代码。求dalao解惑!linux是火帽3.2.2-5,。代码和编译情况如下:


#ifndef MODULE
#define MODULE
#endif

#ifndef __KERNEL__
#define __KERNEL__
#endif

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>



/*hook处理函数*/
unsigned int hook_func(unsigned int hook,
                struct sk_buff *skb,
                const struct net_device *in,
                const struct net_device *out,
                int (*okfn)(struct sk_buff *));





/*注册hook函数数据结构*/
static struct nf_hook_ops my_hook;





/*初始化程序*/
int init_module()
{
        my_hook.hook=hook_func;
        //my_hook.owner=THIS_MODULE;
        my_hook.pf= PF_INET;
        my_hook.hooknum= NF_IP_LOCAL_IN;
        my_hook.priority = NF_IP_PRI_FIRST;

    nf_register_hook(my_hook);//注册入内核

    return 0;
}





/*清除钩子*/
void cleanup_moudule()
{
    nf_unregister_hook(&my_hook);//将用户定义的钩子从内核中删除
}

gcc编译报错:

Myfirewall.c:21: warning: struct net_device' declared inside parameter list
Myfirewall.c:21: warning: its scope is only this definition or declaration, which is probably not what you want
Myfirewall.c:21: warning:
struct sk_buff' declared inside parameter list
Myfirewall.c: In function init_module':
Myfirewall.c:37: invalid use of undefined type
struct nf_hook_ops'
Myfirewall.c:39: invalid use of undefined type struct nf_hook_ops'
Myfirewall.c:40: invalid use of undefined type
struct nf_hook_ops'
Myfirewall.c:41: invalid use of undefined type struct nf_hook_ops'
Myfirewall.c:43:
my_hook' has an incomplete type
Myfirewall.c: At top level:
Myfirewall.c:28: storage size of `my_hook' isn't known

  • 写回答

1条回答

  • dabocaiqq 2016-12-14 15:37
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料