任務,我已經看到了類似的錯誤消息此頁:Nf_hook_ops returns incompatible pointer when assigning to hook_func -C -Linux -Netfilternfhook(網絡過濾器)的錯誤:從兼容的指針類型
但是,它並沒有給出明確的答案,如何解決這個問題。這個問題的作者說,他發現他的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 =不相容指針類型] nfho.hook = hook_func_incoming; ^ CC1:一些警告被視爲錯誤
請讓我知道我應該做的是能夠編譯我的netfilter的,任何幫助表示讚賞!
謝謝!這幫助我解決了這個問題。但是,你能告訴我更多關於第一個和第三個參數的信息嗎?我在網上找不到任何相關文檔(雖然我知道關於第二個參數的信息)。 –