读书人

netfilter程序编译解决方案

发布时间: 2012-02-16 21:30:36 作者: rapoo

netfilter程序编译
我在 网上下了一个 简单的 netfilter程序
如下:
define __KERNEL__
#define MODULE

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/config.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
static struct nf_hook_ops nfho;
unsigned int hook_func(unsigned int hooknum,
struct sk_buff **skb;
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
printf( "a packet go through\n ");
return NF_ACCEPT;
}
int init_module()
{
nfho.hook = hook_func;
//hook function name
nfho.hooknum = NF_IP_PRE_ROUTING;
//position
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
return 0;

}
void cleanup_module()
{
nf_unregister_hook(&nfho);
}
,但是总是编译不通过
错误如下
gcc -c -L/usr/src/linux- 'uname -r '/include -I/usr/include filtertest.c
In file included from filtertest.c:9:
/usr/include/linux/netfilter_ipv4.h:53: `INT_MIN ' undeclared here (not in a function)
/usr/include/linux/netfilter_ipv4.h:53: enumerator value for `NF_IP_PRI_FIRST ' not integer constant
/usr/include/linux/netfilter_ipv4.h:59: `INT_MAX ' undeclared here (not in a function)
/usr/include/linux/netfilter_ipv4.h:59: enumerator value for `NF_IP_PRI_LAST ' not integer constant
filtertest.c:12: parameter `skb ' has just a forward declaration
filtertest.c:11: parameter `hooknum ' has just a forward declaration
filtertest.c:15: warning: `struct net_device ' declared inside parameter list
filtertest.c:15: warning: its scope is only this definition or declaration, which is probably not what you want
filtertest.c:15: warning: `struct sk_buff ' declared inside parameter list
filtertest.c: In function `init_module ':
filtertest.c:22: invalid use of undefined type `struct nf_hook_ops '
filtertest.c:24: invalid use of undefined type `struct nf_hook_ops '
filtertest.c:26: invalid use of undefined type `struct nf_hook_ops '
filtertest.c:26: `PF_INET ' undeclared (first use in this function)
filtertest.c:26: (Each undeclared identifier is reported only once
filtertest.c:26: for each function it appears in.)
filtertest.c:27: invalid use of undefined type `struct nf_hook_ops '


filtertest.c: At top level:
filtertest.c:10: storage size of `nfho ' isn 't known
make: *** [filtertest] Error 1
请高手指点下,多谢

[解决办法]
哈哈!
兄弟算你运气好,正好碰到我也在做防火墙!应该使用这条编译命令
gcc -Wall -O2 -I/usr/src/linux-2.4.20-8/include -DMODULE -D__KERNEL__ -DLINUX -c name.c
linux-2.4.20-8是你的内核的版本替换就可以了!

读书人网 >UNIXLINUX

热点推荐