使用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
struct sk_buff' 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:
Myfirewall.c: In function init_module':
struct nf_hook_ops'
Myfirewall.c:37: invalid use of undefined type
Myfirewall.c:39: invalid use of undefined type struct nf_hook_ops'
struct nf_hook_ops'
Myfirewall.c:40: invalid use of undefined type
Myfirewall.c:41: invalid use of undefined type struct nf_hook_ops'
my_hook' has an incomplete type
Myfirewall.c:43:
Myfirewall.c: At top level:
Myfirewall.c:28: storage size of `my_hook' isn't known