QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1321|回复: 3

[b]对“深入Linux网络核心堆栈”中一段代码的疑问[/b

[复制链接]
发表于 2003-11-6 14:06:28 | 显示全部楼层 |阅读模式
代码来源于“深入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相同。

现在很苦恼!
请问各位高手,如何解决这个问题,请给出一个方案,或可以让该程序编译通过的头文件集合。
谢谢!
发表于 2003-11-6 14:33:48 | 显示全部楼层
maybe you need to install the kernel source. /usr/include/linux/netfilter.h is empty
回复

使用道具 举报

发表于 2003-11-6 17:19:17 | 显示全部楼层
-I /usr/src/linux/include

have a try
回复

使用道具 举报

 楼主| 发表于 2003-11-11 00:49:29 | 显示全部楼层
谢谢。
的确是内核文件少了,我复制一些文件后解决!
“maybe you need to install the kernel source!”
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-18 04:17 , Processed in 0.119319 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表