- 论坛徽章:
- 0
|
netfilter模块代码如下:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/ip.h>
#include <linux/skbuff.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*))
{
return NF_DROP;
}
static int hello_init(void)
{
nfho.hook = hook_func;
nfho.hooknum = NF_IP_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
return 0;
}
static int hello_exit(void)
{
nf_unregister_hook(&nfho);
return 0;
}
module_init(hello_init);
modele_exit(hello_exit);
MODULE_LICENSE("GPL");
makefile代码如下:
ifneq ($(KERNElRELEASE),)
obj-m := hello.o
else
obj-m := hello.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build -I/lib/modules/2.6.26.8-57.fc8/build/include/
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules -I/lib/modules/2.6.26.8-57.fc8/build/include/
endif
碰到问题如下:
[root@localhost net]# make
make -C /lib/modules/2.6.26.8-57.fc8/build -I/lib/modules/2.6.26.8-57.fc8/build/include/ SUBDIRS=/root/net modules -I/lib/modules/2.6.26.8-57.fc8/build/include/
make[1]: Entering directory `/usr/src/kernels/2.6.26.8-57.fc8-i686'
CC [M] /root/net/hello.o
/root/net/hello.c: In function ‘hello_init’:
/root/net/hello.c:23: 警告:从不兼容的指针类型赋值
/root/net/hello.c:24: 错误:‘NF_IP_PRE_ROUTING’ 未声明 (在此函数内第一次使用)
/root/net/hello.c:24: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
/root/net/hello.c:24: 错误:所在的函数内只报告一次。)
/root/net/hello.c: 在顶层:
/root/net/hello.c:38: 警告:数据定义时没有类型或存储类
/root/net/hello.c:38: 警告:在 ‘modele_exit’ 的声明中,类型默认为 ‘int’
/root/net/hello.c:38: 警告:函数声明中出现形参名却未指定类型
make[2]: *** [/root/net/hello.o] 错误 1
make[1]: *** [_module_/root/net] 错误 2
make[1]: Leaving directory `/usr/src/kernels/2.6.26.8-57.fc8-i686'
make: *** [default] 错误 2
提示宏NF_IP_PRE_ROUTING为声明
但指定的头文件所在的目录下的netfilter_ipv4.h对这个宏有定义
[root@localhost net]# cat /lib/modules/2.6.26.8-57.fc8/build/include/linux/netfilter_ipv4.h | grep NF_IP_PRE
#define NF_IP_PRE_ROUTING 0
不明白编译的时候 提示没有这个宏的声明
望大家赐教 |
|