免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1781 | 回复: 1
打印 上一主题 下一主题

[求助]netfilter编程紧急求助!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-07 09:58 |只看该作者 |倒序浏览
我在《深入linux网络核心堆栈》中得到一个例子程序,如下:
#define _KERNEL_
#define MODULE
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/skbuff.h>
#include<linux/netdevice.h>
#include<linux/netfilter.h>
#include<linux/netfilter_ipv4.h>
static struct nf_hook_ops nfho;
static unsigned int
my_hook(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(void)
{
nfho.hook=my_hook;
nfho.hooknum=NF_IP_PRE_ROUTING;
nfho.pf= PF_INET;
nfho.priority=NF_IP_PRI_FIRST;
return nf_register_hook(&nfho);
return 0;

}
void cleanup_module(void)
{
nf_unregister_hook(&nfho);

}
对于以上程序我在redhat 9.0 (linux-2.4.20-8)下通过如下方式编译,但是产生了如下错误,困扰了我很多天,您能告诉我产生错误的原因以及解决的方法吗?
gcc -O -c -I/usr/src/linux-2.4/include test1.c
In file included from test1.c:10:
/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
test1.c:21: warning: `struct net_device' declared inside parameter list
test1.c:21: warning: its scope is only this definition or declaration, which is probably not what you want
test1.c:21: warning: `struct sk_buff' declared inside parameter list
test1.c: In function `init_module':
test1.c:37: invalid use of undefined type `struct nf_hook_ops'
test1.c:38: invalid use of undefined type `struct nf_hook_ops'
test1.c:39: invalid use of undefined type `struct nf_hook_ops'
test1.c:40: invalid use of undefined type `struct nf_hook_ops'
/usr/include/linux/byteorder/swab.h: At top level:
test1.c:14: storage size of `nfho' isn't known
     nf_hook_ops数据结构不是在netfilter.h头文件里面吗,为什么还会这样报错呢?希望好心人帮帮忙。不胜感激。

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-11-17 06:20:00
2 [报告]
发表于 2010-06-21 10:54 |只看该作者
回复 1# qpbn10


    编译内核模块程序不能像你那样简单用gcc命令,那样是不行的,并且2.4和2.6内核模板的编译方式也不相同,所以请找一个关于内核编程的资料看看就可以明白问题了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP