I saw this page with a similar error message: Nf_hook_ops returns an incompatible pointer when assigning hook_func -C -Linux -Netfilter
However, he did not give a clear answer to the question of how to solve the problem. The author of this question says that he found that his netfilter.h is in a different place, which caused problems, but for me I found out that all four files are included in the correct directory (usr / src / linux-headers-4.8. 0-22 -generic / include / linux in my case).
Below is my code that should help clarify better.
#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; }
The exact error message is:
error: assignment from an incompatible pointer type [-Werror = incompatible-pointer types] nfho.hook = hook_func_incoming; ^ cc1: some warnings are treated as errors
Please let me know what I have to do to compile my netfilter, any help would be appreciated!
source share