morry 发表于 2005-4-17 13:06:07

【求助】急!linux新手向大家求教 先谢了!

--------------------------------------------------------------------------------

我最近在做毕业设计,题目是基于netfilter的ip包过滤,我先写了如下一个简单的内核模块,完成的功能是丢弃所有接受到的icmp包,但是一编译就出现很多行错误,我看不懂错在哪里,所以发帖子求助,请帮我看看好吗?程序不长,不会占用你太多时间的。谢谢了!

我用 gcc -c 文件名 编译的。

#ifndef __KERNEL__
#define __KERNEL__
#endif

#ifndef MODULE
#define MODULE
#endif

#include "linux/module.h"
#include "linux/kernel.h"
#include "linux/init.h"
#include "linux/types.h"
#include "linux/netdevice.h"
#include "linux/skbuff.h"
#include "linux/netfilter_ipv4.h"
#include "linux/inet.h"
#include "linux/in.h"
#include "linux/ip.h"
#include "asm/semaphore.h"
#include "linux/netfilter.h"


static unsigned int dropicmp(unsigned int hook,
struct sk_buff **pskb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct iphdr *iph = (*pskb)->nh.iph;
if(iph->protocol == IPPROTO_ICMP)
{
printk("Drop ICMP Packet!\n");
return NF_DROP;
}

else return NF_ACCEPT;
}

static struct nf_hook_ops myhook
= {{NULL ,NULL},dropicmp, PF_INET,NF_IP_PRE_ROUTING,NF_IP_PRI_FILTER-1};

static int init_module(void)
{

return nf_register_hook(&myhook);
}

static void cleanup_module(void)
{
nf_unregister_hook(&myhook);
}
页: [1]
查看完整版本: 【求助】急!linux新手向大家求教 先谢了!