我看到这个页面有类似的错误信息:Nf_hook_ops returns incompatible pointer when assigning to hook_func -C -Linux -Netfilter
但是,对于如何解决这个问题,并没有给出明确的答案。该问题的作者说他发现他的 netfilter.h 位于导致问题的其他地方,但对我来说,我发现所有包含的四个文件都在正确的目录 (usr/src/linux-headers-4.8.h) 中。在我的例子中是 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,我们将不胜感激!
最佳答案
在(恕我直言)最新(已发布)netfilter version ,nf_hookfn
(nf_hook_ops.hook
的基类)定义如下:
typedef unsigned int nf_hookfn(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state);
你的函数hook_func_incoming
不匹配这个签名,你应该采用它。
关于c - nfhook (netfilter) 错误 : assignment from incompatible pointer type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44150093/