当前位置: 技术问答>linux和unix
用gcc编译有一堆堆错误,高手帮忙啊
来源: 互联网 发布时间:2015-08-17
本文导语: 源代码是用hook 抓包;如下: #define MODULE #include #include #include #include #include #include #include #include #include #include #include #include #include static struct nf_hook_ops nfho; unsigned cha...
源代码是用hook 抓包;如下:
#define MODULE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static struct nf_hook_ops nfho;
unsigned char* ip = "x7fx00x00x01";
unsigned char* drop_ip = "xC0xA8x08xC9";
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 *))
{
struct sk_buff* sb = *skb;
struct tcphdr *tcp = NULL;
unsigned int d_ip ,s_ip = 0;
unsigned int d_port = 0,s_port = 0;
if( sb->nh.iph->protocol == IPPROTO_TCP )
tcp = (struct tcphdr *)((sb->data) + (sb->nh.iph->ihl * 4));
d_ip = sb->nh.iph->daddr;
s_ip = sb->nh.iph->saddr;
if( tcp )
{
d_port = tcp->source;
s_port = tcp->dest;
}
if( sb->nh.iph->saddr == *(unsigned int*)drop_ip )
{
printk( "Droped packet from ... %d.%d.%d.%d:%dn", NIPQUAD(s_ip), s_port );
return NF_DROP;
}
// printk( "FROM:%d.%d.%d.%d:%d TO:%d.%d.%d.%d:%d ETH:%sn",
// NIPQUAD(s_ip), s_port, NIPQUAD(d_ip), d_port, in->name );
return NF_ACCEPT;
}
int init_module()
{
printk( "begin init module test2n" );
nfho.hook = hook_func;
nfho.hooknum = NF_IP_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
printk("init module test2n");
return 0;
}
void cleanup_module()
{
nf_unregister_hook(&nfho);
printk("cleanup module test2n");
}
MODULE_LICENSE("GPL");
用“gcc -c test3.c -o test3.o -Wall”编译;有如下错误
In file included from /usr/include/linux/cpumask.h:8,
from /usr/include/linux/sched.h:14,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/linux/bitmap.h: In function `bitmap_shift_right':
/usr/include/linux/bitmap.h:85: error: `__shr_tmp' undeclared (first use in this
function)
/usr/include/linux/bitmap.h:85: error: (Each undeclared identifier is reported o
nly once
/usr/include/linux/bitmap.h:85: error: for each function it appears in.)
/usr/include/linux/bitmap.h: In function `bitmap_shift_left':
/usr/include/linux/bitmap.h:98: error: `__shl_tmp' undeclared (first use in this
function)
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/linux/cpumask.h:10:5: missing binary operator before token "("
/usr/include/linux/cpumask.h:34:5: missing binary operator before token "("
In file included from /usr/include/asm/siginfo.h:4,
from /usr/include/linux/signal.h:7,
from /usr/include/linux/sched.h:24,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/asm-generic/siginfo.h: At top level:
/usr/include/asm-generic/siginfo.h:53: error: size of array `_pad' is too large
In file included from /usr/include/linux/gfp.h:4,
from /usr/include/linux/slab.h:15,
from /usr/include/linux/percpu.h:4,
from /usr/include/linux/sched.h:30,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/linux/mmzone.h:333: error: parse error before '(' token
/usr/include/linux/mmzone.h:334: error: parse error before numeric constant
In file included from /usr/include/linux/module.h:20,
from hook.c:14:
/usr/include/asm/module.h:54:2: #error unknown processor family
In file included from /usr/include/linux/mm.h:206,
from /usr/include/linux/skbuff.h:26,
from hook.c:16:
/usr/include/linux/page-flags.h:119: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclar
ed here (not in a function)
/usr/include/linux/page-flags.h:119: error: requested alignment is not a constan
t
In file included from hook.c:18:
/usr/include/linux/ip.h:84:22: net/sock.h: No such file or directory
/usr/include/linux/ip.h:86:22: net/flow.h: No such file or directory
In file included from hook.c:18:
/usr/include/linux/ip.h:145: error: field `fl' has incomplete type
/usr/include/linux/ip.h:155: error: field `sk' has incomplete type
In file included from hook.c:19:
/usr/include/linux/tcp.h:193:22: net/sock.h: No such file or directory
In file included from hook.c:19:
/usr/include/linux/tcp.h:381: error: field `sk' has incomplete type
In file included from /usr/include/linux/irq.h:20,
from /usr/include/asm/hardirq.h:6,
from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/asm/irq.h:16:25: irq_vectors.h: No such file or directory
In file included from /usr/include/asm/hardirq.h:6,
from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/linux/irq.h:68: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared here
(not in a function)
/usr/include/linux/irq.h:68: error: requested alignment is not a constant
/usr/include/linux/irq.h:70: error: `NR_IRQS' undeclared here (not in a function
)
In file included from /usr/include/linux/irq.h:72,
from /usr/include/asm/hardirq.h:6,
from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/asm/hw_irq.h:28: error: `NR_IRQ_VECTORS' undeclared here (not in a function)
/usr/include/asm/hw_irq.h:31: error: `NR_IRQS' undeclared here (not in a functio n)
In file included from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/asm/hardirq.h:13: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared her e (not in a function)
/usr/include/asm/hardirq.h:13: error: requested alignment is not a constant
hook.c: In function `init_module':
hook.c:64: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:65: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:66: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:67: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:69: warning: implicit declaration of function `nf_register_hook'
hook.c: In function `cleanup_module':
hook.c:76: warning: implicit declaration of function `nf_unregister_hook'
hook.c:80:23: warning: no newline at end of file
/usr/include/linux/netdevice.h: At top level:
hook.c:28: error: storage size of `nfho' isn't known
#define MODULE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static struct nf_hook_ops nfho;
unsigned char* ip = "x7fx00x00x01";
unsigned char* drop_ip = "xC0xA8x08xC9";
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 *))
{
struct sk_buff* sb = *skb;
struct tcphdr *tcp = NULL;
unsigned int d_ip ,s_ip = 0;
unsigned int d_port = 0,s_port = 0;
if( sb->nh.iph->protocol == IPPROTO_TCP )
tcp = (struct tcphdr *)((sb->data) + (sb->nh.iph->ihl * 4));
d_ip = sb->nh.iph->daddr;
s_ip = sb->nh.iph->saddr;
if( tcp )
{
d_port = tcp->source;
s_port = tcp->dest;
}
if( sb->nh.iph->saddr == *(unsigned int*)drop_ip )
{
printk( "Droped packet from ... %d.%d.%d.%d:%dn", NIPQUAD(s_ip), s_port );
return NF_DROP;
}
// printk( "FROM:%d.%d.%d.%d:%d TO:%d.%d.%d.%d:%d ETH:%sn",
// NIPQUAD(s_ip), s_port, NIPQUAD(d_ip), d_port, in->name );
return NF_ACCEPT;
}
int init_module()
{
printk( "begin init module test2n" );
nfho.hook = hook_func;
nfho.hooknum = NF_IP_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
printk("init module test2n");
return 0;
}
void cleanup_module()
{
nf_unregister_hook(&nfho);
printk("cleanup module test2n");
}
MODULE_LICENSE("GPL");
用“gcc -c test3.c -o test3.o -Wall”编译;有如下错误
In file included from /usr/include/linux/cpumask.h:8,
from /usr/include/linux/sched.h:14,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/linux/bitmap.h: In function `bitmap_shift_right':
/usr/include/linux/bitmap.h:85: error: `__shr_tmp' undeclared (first use in this
function)
/usr/include/linux/bitmap.h:85: error: (Each undeclared identifier is reported o
nly once
/usr/include/linux/bitmap.h:85: error: for each function it appears in.)
/usr/include/linux/bitmap.h: In function `bitmap_shift_left':
/usr/include/linux/bitmap.h:98: error: `__shl_tmp' undeclared (first use in this
function)
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/linux/cpumask.h:10:5: missing binary operator before token "("
/usr/include/linux/cpumask.h:34:5: missing binary operator before token "("
In file included from /usr/include/asm/siginfo.h:4,
from /usr/include/linux/signal.h:7,
from /usr/include/linux/sched.h:24,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/asm-generic/siginfo.h: At top level:
/usr/include/asm-generic/siginfo.h:53: error: size of array `_pad' is too large
In file included from /usr/include/linux/gfp.h:4,
from /usr/include/linux/slab.h:15,
from /usr/include/linux/percpu.h:4,
from /usr/include/linux/sched.h:30,
from /usr/include/linux/module.h:9,
from hook.c:14:
/usr/include/linux/mmzone.h:333: error: parse error before '(' token
/usr/include/linux/mmzone.h:334: error: parse error before numeric constant
In file included from /usr/include/linux/module.h:20,
from hook.c:14:
/usr/include/asm/module.h:54:2: #error unknown processor family
In file included from /usr/include/linux/mm.h:206,
from /usr/include/linux/skbuff.h:26,
from hook.c:16:
/usr/include/linux/page-flags.h:119: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclar
ed here (not in a function)
/usr/include/linux/page-flags.h:119: error: requested alignment is not a constan
t
In file included from hook.c:18:
/usr/include/linux/ip.h:84:22: net/sock.h: No such file or directory
/usr/include/linux/ip.h:86:22: net/flow.h: No such file or directory
In file included from hook.c:18:
/usr/include/linux/ip.h:145: error: field `fl' has incomplete type
/usr/include/linux/ip.h:155: error: field `sk' has incomplete type
In file included from hook.c:19:
/usr/include/linux/tcp.h:193:22: net/sock.h: No such file or directory
In file included from hook.c:19:
/usr/include/linux/tcp.h:381: error: field `sk' has incomplete type
In file included from /usr/include/linux/irq.h:20,
from /usr/include/asm/hardirq.h:6,
from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/asm/irq.h:16:25: irq_vectors.h: No such file or directory
In file included from /usr/include/asm/hardirq.h:6,
from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/linux/irq.h:68: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared here
(not in a function)
/usr/include/linux/irq.h:68: error: requested alignment is not a constant
/usr/include/linux/irq.h:70: error: `NR_IRQS' undeclared here (not in a function
)
In file included from /usr/include/linux/irq.h:72,
from /usr/include/asm/hardirq.h:6,
from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/asm/hw_irq.h:28: error: `NR_IRQ_VECTORS' undeclared here (not in a function)
/usr/include/asm/hw_irq.h:31: error: `NR_IRQS' undeclared here (not in a functio n)
In file included from /usr/include/linux/interrupt.h:11,
from /usr/include/linux/netdevice.h:490,
from hook.c:21:
/usr/include/asm/hardirq.h:13: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared her e (not in a function)
/usr/include/asm/hardirq.h:13: error: requested alignment is not a constant
hook.c: In function `init_module':
hook.c:64: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:65: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:66: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:67: error: invalid use of undefined type `struct nf_hook_ops'
hook.c:69: warning: implicit declaration of function `nf_register_hook'
hook.c: In function `cleanup_module':
hook.c:76: warning: implicit declaration of function `nf_unregister_hook'
hook.c:80:23: warning: no newline at end of file
/usr/include/linux/netdevice.h: At top level:
hook.c:28: error: storage size of `nfho' isn't known
|
这个代码怎么看着那么眼熟呢-_-!
|
搞错路径了吧?去掉前面的linux看看
|
是不是编译前的配置有误?如与你的硬件不匹配?