Nf_hook_ops在分配给hook_func -C -Linux -Netfilter时返回不兼容的指针

我试图在Ubuntu 16.04 LTS上编写自己的Netfilter内核模块,我试图将hook_func分配给nfho.hook,但是我收到以下错误:

error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types] nfho.hook = hook_func;

我已经看过其他解决方案,大多数都是双重检查参数,包括将*skb更改为**skb 。 我已经读过,参数可能取决于内核版本,但无法找到如何找到要传递的正确参数。

我怎样才能使它工作,我如何检查应该在我的内核版本的hook_func中传递什么参数?

完整代码:

 #include  #include  #include  #include  #include  #include  #include  static struct nf_hook_ops nfho; //struct holding set of hook function options // function to be called by hook 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 *)) { struct iphdr *ip_header = (struct iphdr *)skb_network_header(skb); struct tcphdr *tcp_header; if (ip_header->protocol == 6) { printk(KERN_INFO "TCP Packet\n"); tcp_header = (struct tcphdr *)(skb_transport_header(skb)+20); printk(KERN_INFO "Source Port: %u\n", tcp_header->source); } return NF_ACCEPT; } int init_module() { nfho.hook = hook_func; nfho.hooknum = NF_INET_PRE_ROUTING; nfho.pf = PF_INET; nfho.priority = NF_IP_PRI_FIRST; nf_register_hook(&nfho); return 0; }