[b]对“深入Linux网络核心堆栈”中一段代码的疑问[/b
代码来源于“深入Linux网络核心堆栈”代码如下:
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
/* 用于注册我们的函数的数据结构 */
static struct nf_hook_ops nfho;
/* 注册的hook函数的实现 */
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 *))
{
return NF_DROP; /* 丢弃所有的数据包 */
}
/* 初始化程序 */
int init_module()
{
/* 填充我们的hook数据结构 */
nfho.hook = hook_func; /* 处理函数 */
nfho.hooknum = NF_IP_PRE_ROUTING; /* 使用IPv4的第一个hook */
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST; /* 让我们的函数首先执行 */
nf_register_hook(&nfho);
return 0;
}
/* 清除程序 */
void cleanup_module()
{
nf_unregister_hook(&nfho);
}
在Red9中编译出错,错误信息如下:
/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
net1.c:17: warning: `struct net_device' declared inside parameter list
net1.c:17: warning: its scope is only this definition or declaration, which is probably not what you want
net1.c:17: warning: `struct sk_buff' declared inside parameter list
net1.c: In function `init_module':
net1.c:26: invalid use of undefined type `struct nf_hook_ops'
net1.c:27: invalid use of undefined type `struct nf_hook_ops'
net1.c:28: invalid use of undefined type `struct nf_hook_ops'
net1.c:28: `PF_INET' undeclared (first use in this function)
net1.c:28: (Each undeclared identifier is reported only once
net1.c:28: for each function it appears in.)
net1.c:29: invalid use of undefined type `struct nf_hook_ops'
但在红旗4下编译成功。我经过比较引用的头文件,发现在include中Linux和Asm下的文件有很大的区别。
两个Linux的内核都是2.4.20-8,我现在要把该程序移植到Red Mat Advanced server3 (2.4.21-3)下发现,出错的信息和Red 9相同。
现在很苦恼!
请问各位高手,如何解决这个问题,请给出一个方案,或可以让该程序编译通过的头文件集合。
谢谢! maybe you need to install the kernel source. /usr/include/linux/netfilter.h is empty -I /usr/src/linux/include
have a try 谢谢。
的确是内核文件少了,我复制一些文件后解决!
“maybe you need to install the kernel source!”
页:
[1]