LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1677|回复: 1

关于netfilter模块的编程小问题

[复制链接]
发表于 2004-4-14 14:53:08 | 显示全部楼层 |阅读模式
我的源代码是:
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/config.h>
#include <linux/ip.h>
#include <linux/netfilter.h>

static unsigned int linuxmag_hook(unsigned int hook, struct sk_buff **pskb,const struct net_device *indev, const struct net_device *outdev, int (*okfn)(struct sk_buff *))
{
        return NF_DROP;
}

static struct nf_hook_ops linuxmag_ops={{NULL,NULL},linuxmag_hook,PF_INET,NF_IP_LOCAL_OUT,NF_IP_PRI_FILTER-1};

int init_module(void)
{
    return nf_register_hook(&linuxmag_ops);
}

void cleanup_module(void)
{
    nf_unregister_hook(&linuxmag_ops);
}
编译:gcc -c temp.c
结果却出现如下错误:
[yang@otest yang]$ gcc -c temp.c
temp.c:8: warning: `struct net_device' declared inside parameter list
temp.c:8: warning: its scope is only this definition or declaration, which is probably not what you want
temp.c:8: warning: `struct sk_buff' declared inside parameter list
temp.c:13: variable `linuxmag_ops' has initializer but incomplete type
temp.c:13: extra brace group at end of initializer
temp.c:13: (near initialization for `linuxmag_ops')
temp.c:13: `NULL' undeclared here (not in a function)
temp.c:13: `NULL' undeclared here (not in a function)
temp.c:13: warning: excess elements in struct initializer
temp.c:13: warning: (near initialization for `linuxmag_ops')
temp.c:13: warning: excess elements in struct initializer
temp.c:13: warning: (near initialization for `linuxmag_ops')
temp.c:13: `PF_INET' undeclared here (not in a function)
temp.c:13: warning: excess elements in struct initializer
temp.c:13: warning: (near initialization for `linuxmag_ops')
temp.c:13: `NF_IP_LOCAL_OUT' undeclared here (not in a function)
temp.c:13: warning: excess elements in struct initializer
temp.c:13: warning: (near initialization for `linuxmag_ops')
temp.c:13: `NF_IP_PRI_FILTER' undeclared here (not in a function)
temp.c:13: warning: excess elements in struct initializer
temp.c:13: warning: (near initialization for `linuxmag_ops')
temp.c:13: storage size of `linuxmag_ops' isn't known
不知该怎么解决!郁闷了很久了。希望那位高手指教一二。^_^
先谢了。
发表于 2007-8-5 19:44:07 | 显示全部楼层
好老的帖子,不知道还有没有人看了。
我刚才也试了,确实有问题,不过查看/linux/include/linux/netfiler.c后,会发现是struct nf_hook_ops的问题,可能是内核版本太新了,这个结构变成六个参数了,如下:
struct nf_hook_ops
{
        struct list_head list;

        /* User fills in from here down. */
        nf_hookfn *hook;
        struct module *owner;
        int pf;
        int hooknum;
        /* Hooks are ordered in ascending priority. */
        int priority;
};
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表