【发布时间】:2017-10-24 07:24:42
【问题描述】:
我看到这个页面有类似的错误信息:Nf_hook_ops returns incompatible pointer when assigning to hook_func -C -Linux -Netfilter
但是,它没有给出如何解决问题的明确答案。该问题的作者说他发现他的 netfilter.h 位于导致问题的其他地方,但对我来说,我发现包含的所有四个文件都在正确的目录中(usr/src/linux-headers-4.8. 0-22-generic/include/linux 在我的例子中)。
以下是我的代码,应该有助于更好地澄清。
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
static struct nf_hook_ops nfho;
unsigned int hook_func_incoming(unsigned int hooknum, struct sk_buff *sskb,
const struct net_device *in, const struct net_device *out, int (*okfn)
(struct sk_buff *)){
return NF_DROP;
}
int init_module(){
nfho.hook = hook_func_incoming;
nfho.hooknum = NF_INET_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
printk(KERN_INFO "SIMPLE FIREWALL LOADED\n");
return 0;
}
确切的错误信息是这样的:
错误:来自不兼容指针类型的赋值 [-Werror=incompatible-pointer-types] nfho.hook = hook_func_incoming; ^ cc1:一些警告被视为错误
请让我知道我应该怎么做才能编译我的 netfilter,感谢任何帮助!
【问题讨论】:
标签: c linux-kernel kernel-module netfilter