请高手指点:这个模块为什么不能编译通过

michealzoe 2003-10-16 02:35:14
请高手指点:这个模块为什么不能编译通过
#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

...全文
25 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liupengfei81 2003-10-17
  • 打赏
  • 举报
回复
up
fierygnu 2003-10-17
  • 打赏
  • 举报
回复
const struct net_device *in
这个结构定义在什么地方?编译器没找到。
zeng_xiangyang 2003-10-17
  • 打赏
  • 举报
回复
up

23,114

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧