|
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/string.h>
static struct nf_hook_ops nfho;
static char *drop_if="lo";
static char *temp="eth0";
int init_module(void);
void cleanup_module(void);
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 *))
{
if ( strcmp(in->name,drop_if) == 0 ){ //this is line 18
}
return NF_ACCEPT;
}
int init_module()
{
nfho.hook = hook_func; /* 处理函数 */
nfho.hooknum = NF_IP_PRE_ROUTING; /* 使用IPv4的第一个hook */
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST; /* 让我们的函数首先执行 */
nf_register_hook(&nfho); printk("a net hook installed\n");
return 0;
}
void cleanup_module()
{
nf_unregister_hook(&nfho);
printk("uninstall a net hook\n");
}
Makefile 的内容为:
TARGET := nethook
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
//CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${INCLUDE}
CC := gcc
${TARGET}.o: ${TARGET}.c
.PHONY: clean
每次编译总是出现如下错误信息:
nethook #make
gcc -O2 -DMODULE -D__KERNEL__ -isystem /lib/modules/`uname -r`/build/include -c -o nethook.o nethook.c
nethook.c: In function `hook_func':
nethook.c:18: dereferencing pointer to incomplete type
make: *** [nethook.o] Error 1 |
|