日期:2014-05-16  浏览次数:20746 次

netfilter程序编译
我在   网上下了一个   简单的   netfilter程序
如下:  
define   __KERNEL__
#define   MODULE

#include   <linux/kernel.h>
#include   <linux/module.h>
#include   <linux/config.h>
#include   <linux/netfilter.h>
#include   <linux/netfilter_ipv4.h>
static   struct   nf_hook_ops   nfho;
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   *))
{
printf( "a   packet   go   through\n ");
return   NF_ACCEPT;  
}
int   init_module()
{
nfho.hook   =   hook_func;
//hook   function   name
nfho.hooknum   =   NF_IP_PRE_ROUTING;
//position
nfho.pf   =   PF_INET;
nfho.priority   =   NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
return   0;

}
void   cleanup_module()
{
nf_unregister_hook(&nfho);
}
,但是总是编译不通过  
错误如下
gcc   -c     -L/usr/src/linux- 'uname   -r '/include   -I/usr/include   filtertest.c
In   file   included   from   filtertest.c:9:
/usr/include/linux/netfilter_ipv4.h:53:   `INT_MIN '   undeclared   here   (not   in   a   function)
/usr/include/linux/netfilter_ipv4.h:53:   enumerator   value   for   `NF_IP_PRI_FIRST '   not   integer   constant
/usr/include/linux/netfilter_ipv4.h:59:   `INT_MAX '   undeclared   here   (not   in   a   function)
/usr/include/linux/netfilter_ipv4.h:59:   enumerator   value   for   `NF_IP_PRI_LAST '   not   integer   constant
filtertest.c:12:   parameter   `skb '   has   just   a   forward   declaration
filtertest.c:11:   parameter   `hooknum '   has   just   a   forward   declaration
filtertest.c:15:   warning:   `struct   net_device '   declared   inside   parameter   list
filtertest.c:15:   warning:   its   scope   is   only   this   definition   or   declaration,   which   is   probably   not   what   you   want
filtertest.c:15:   warning:   `struct   sk_buff '   declared   inside   parameter   list
filtertest.c:   In   function   `init_module ':
filtertest.c:22:   invalid   use   of   undefined   type   `struct   nf_hook_ops '
filtertest.c:24:   invalid   use   of   undefined   type   `struct   nf_hook_ops '
filtertest.c:26:   invalid   use   of   undefined   type   `struct   nf_hook_ops '
filtertest.c:26:   `PF_INET '   undeclared   (first   use   in   this   function)
filtertest.c:26:   (Each   undeclared   identifier   is   reported   only   once
filtertest.c:26:   for   each   function   it &n