免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1266 | 回复: 0
打印 上一主题 下一主题

[C] netfilter模块编译出错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-29 17:14 |只看该作者 |倒序浏览
本帖最后由 shuimuyq 于 2015-07-29 17:16 编辑

源码如下:
/* Sample code to install a Netfilter hook function that will
* drop all incoming packets. */

#define __KERNEL__
#define MODULE

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

/* This is the structure we shall use to register our function */
static struct nf_hook_ops nfho;

/* This is the hook function itself */
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 *))
{
    return NF_DROP;           /* Drop ALL packets */
}

/* Initialisation routine */
int init_module()
{
    /* Fill in our hook structure */
    nfho.hook = hook_func;         /* Handler function */
    nfho.hooknum  = NF_IP_PRE_ROUTING; /* First hook for IPv4 */
    nfho.pf       = PF_INET;
    nfho.priority = NF_IP_PRI_FIRST;   /* Make our function first */

    nf_register_hook(&nfho);
   
    return 0;
}
       
/* Cleanup routine */
void cleanup_module()
{
    nf_unregister_hook(&nfho);
}




makefile如下:
obj-m += dropall.o

all: $(obj-m)
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean




编译错误信息如下:
cc    -c -o dropall.o dropall.c
dropall.c:7:26: error: linux/module.h: No such file or directory
In file included from dropall.c:9:
/usr/include/linux/netfilter.h:64: error: field ‘in’ has incomplete type
/usr/include/linux/netfilter.h:65: error: field ‘in6’ has incomplete type
In file included from dropall.c:10:
/usr/include/linux/netfilter_ipv4.h:53: error: ‘INT_MIN’ undeclared here (not in a function)
/usr/include/linux/netfilter_ipv4.h:64: error: ‘INT_MAX’ undeclared here (not in a function)
dropall.c:20: warning: ‘struct net_device’ declared inside parameter list
dropall.c:20: warning: its scope is only this definition or declaration, which is probably not what you want
dropall.c:20: warning: ‘struct sk_buff’ declared inside parameter list
dropall.c: In function ‘init_module’:
dropall.c:29: error: invalid use of undefined type ‘struct nf_hook_ops’
dropall.c:30: error: invalid use of undefined type ‘struct nf_hook_ops’
dropall.c:31: error: invalid use of undefined type ‘struct nf_hook_ops’
dropall.c:31: error: ‘PF_INET’ undeclared (first use in this function)
dropall.c:31: error: (Each undeclared identifier is reported only once
dropall.c:31: error: for each function it appears in.)
dropall.c:32: error: invalid use of undefined type ‘struct nf_hook_ops’
make: *** [dropall.o] Error 1



不了解模块编译要怎么处理,求帮助!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP