linux 模块化编译,linux里模块编译的问题

我想试一下使用往netfliter上某个hook点装个钩子函数上去,然后在网上找了一下相关的文章,然后把网上的代码大致改了一下,如下:

#include

#include

#include

#include

#include

#include

#include

#include

#include

static unsigned int myhook_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 struct nf_hook_ops nfho={

.hook = myhook_func,

.owner = THIS_MODULE,

.pf = PF_INET,

.hooknum = NF_IP_LOCAL_OUT,

.priority = NF_IP_PRI_FIRST,

};

static int __init myhook_init(void)

{

return nf_register_hook(&nfho);

}

static void __exit myhook_fini(void)

{

nf_unregister_hook(&nfho);

}

module_init(myhook_init);

module_exit(myhook_fini);

/******************************************************/

Makefile如下:

ifneq ($(KERNELRELEASE),)

mymodule-objs:=test0.c

obj-m += test0.o

else

PWD := $(shell pwd)

KVER := $(shell uname -r)

KDIR := /lib/modules/$(KVER)/build

all:

$(MAKE) -C $(KDIR) M=$(PWD) modules

endif

/**********************************************/

make以后的结果如下:

make -C /lib/modules/3.16.0-23-generic/build M=/home/author/workspace/TestNF modules

make[1]: Entering directory '/usr/src/linux-headers-3.16.0-23-generic'

CC [M] /home/author/workspace/TestNF/test0.o

/home/author/workspace/TestNF/test0.c:17:9: warning: initialization from incompatible pointer type

.hook = myhook_func,

^

/home/author/workspace/TestNF/test0.c:17:9: warning: (near initialization for ‘nfho.hook’)

/home/author/workspace/TestNF/test0.c:20:27: error: ‘NF_IP_LOCAL_OUT’ undeclared here (not in a function)

.hooknum = NF_IP_LOCAL_OUT,

^

scripts/Makefile.build:263: recipe for target '/home/author/workspace/TestNF/test0.o' failed

make[2]: *** [/home/sineatos/workspace/TestNF/test0.o] Error 1

Makefile:1345: recipe for target '_module_/home/author/workspace/TestNF' failed

make[1]: *** [_module_/home/author/workspace/TestNF] Error 2

make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-23-generic'

Makefile:11: recipe for target 'all' failed

make: *** [all] Error 2

请问究竟是什么问题?

需要怎么解决?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值