|
|
我想要给netfilter添加一个钩子,原理都弄明白了,但是试了一下linux magazine上 给的例子程序,编译错误太多了,主要是所包含的头文件 的错误.我的系统是REDHAT ES3
原文件:
- #include <linux/config.h>
- #include <linux/module.h>
- #include <linux/netfilter_ipv4.h>
- #include <linux/ip.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 *))
- {
-
- /* Get a handle to the packet data */
- unsigned char *data = (void *)(*pskb)->nh.iph +
- (*pskb)->nh.iph->ihl*4;
-
- (*pskb)->nfcache |= NFC_UNKNOWN;
-
- switch ((*pskb)->len) {
- case 100:
- printk("linuxmag: corrupting packet\n");
- data[99]++;
- (*pskb)->nfcache |= NFC_ALTERED;
- return NF_ACCEPT;
-
- case 200:
- printk("linuxmag: dropping packet\n");
- return NF_DROP;
-
- default:
- return NF_ACCEPT;
- }
- }
-
-
- static struct nf_hook_ops linuxmag_ops
- = { { NULL, NULL }, linuxmag_hook,
- PF_INET, NF_IP_LOCAL_OUT,
- NF_IP_PRI_FILTER-1 };
- static int __init init(void)
- {
- return nf_register_hook(&linuxmag_ops);
- }
-
- static void __exit fini(void)
- {
- nf_unregister_hook(&linuxmag_ops);
- }
-
- module_init(init);
- module_exit(fini);
复制代码
编译错误结果:
[root@anuode root]# gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c linuxmag.c
In file included from linuxmag.c:3:
/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
linuxmag.c:11: warning: `struct net_device' declared inside parameter list
linuxmag.c:11: warning: its scope is only this definition or declaration, which is probably not what you want
linuxmag.c:11: warning: `struct sk_buff' declared inside parameter list
linuxmag.c: In function `linuxmag_hook':
linuxmag.c:15: dereferencing pointer to incomplete type
linuxmag.c:16: dereferencing pointer to incomplete type
linuxmag.c:18: dereferencing pointer to incomplete type
linuxmag.c:20: dereferencing pointer to incomplete type
linuxmag.c:22: warning: implicit declaration of function `printk'
linuxmag.c:24: dereferencing pointer to incomplete type
linuxmag.c: At top level:
linuxmag.c:38: variable `linuxmag_ops' has initializer but incomplete type
linuxmag.c:38: extra brace group at end of initializer
linuxmag.c:38: (near initialization for `linuxmag_ops')
linuxmag.c:38: `NULL' undeclared here (not in a function)
linuxmag.c:38: `NULL' undeclared here (not in a function)
linuxmag.c:38: warning: excess elements in struct initializer
linuxmag.c:38: warning: (near initialization for `linuxmag_ops')
linuxmag.c:38: warning: excess elements in struct initializer
linuxmag.c:38: warning: (near initialization for `linuxmag_ops')
linuxmag.c:39: `PF_INET' undeclared here (not in a function)
linuxmag.c:39: warning: excess elements in struct initializer
linuxmag.c:39: warning: (near initialization for `linuxmag_ops')
linuxmag.c:39: warning: excess elements in struct initializer
linuxmag.c:39: warning: (near initialization for `linuxmag_ops')
linuxmag.c:40: warning: excess elements in struct initializer
linuxmag.c:40: warning: (near initialization for `linuxmag_ops')
linuxmag.c:43: syntax error before "init"
linuxmag.c:44: warning: return type defaults to `int'
linuxmag.c: In function `init':
linuxmag.c:45: warning: implicit declaration of function `nf_register_hook'
linuxmag.c: At top level:
linuxmag.c:48: syntax error before "fini"
linuxmag.c:49: warning: return type defaults to `int'
linuxmag.c: In function `fini':
linuxmag.c:50: warning: implicit declaration of function `nf_unregister_hook'
linuxmag.c: At top level:
linuxmag.c:53: warning: type defaults to `int' in declaration of `module_init'
linuxmag.c:53: warning: parameter names (without types) in function declaration
linuxmag.c:53: warning: data definition has no type or storage class
linuxmag.c:54: warning: type defaults to `int' in declaration of `module_exit'
linuxmag.c:54: warning: parameter names (without types) in function declaration
linuxmag.c:54: warning: data definition has no type or storage class
linuxmag.c:38: storage size of `linuxmag_ops' isn't known |
|