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个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐