Chinaunix
标题:
linux内核3.0.0-通过sk_buff读取tcp端口的问题!急!谢!
[打印本页]
作者:
lanqiucoco
时间:
2012-04-30 15:25
标题:
linux内核3.0.0-通过sk_buff读取tcp端口的问题!急!谢!
我现在用的是ubuntu 11.10,内核是3.0.0-17
问题是我最近想写一个基于netfilter框架的流量程序。现在struct sk_buff结构变了
struct sk_buff {
.
.
sk_buff_data_t transport_header;
sk_buff_data_t network_header;
sk_buff_data_t mac_header;
.
.
}
现在我在框架中挂一个钩子,怎么运用这个sk_buff结构读出包的目的端口啊?急!!谢谢!
#include <linux/module.h>
#include <linux/tcp.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
MODULE_LICENSE("GPL");
unsigned char *deny_port = "\x00\x16";
struct nf_hook_ops hookops;
struct tcphdr *tcpth;
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 *))
{
tcpth = NULL;
tcpth = tcp_hdr(skb);
printk("source port = %s\n",tcpth->source);
printk("dest port = %d\n",tcpth->dest);
printk("len = %d\n",skb->len);
return NF_ACCEPT;
}
static int example_init(void)
{
hookops.hook = hook_func;
hookops.hooknum = NF_INET_LOCAL_IN;
hookops.pf = PF_INET;
hookops.priority = NF_IP_PRI_FIRST;
nf_register_hook(&hookops);
printk("example module install into kernel!\n");
return 0;
}
static void example_exit(void)
{
nf_unregister_hook(&hookops);
printk("example module removed from kernel!\n");
}
module_init(example_init);
module_exit(example_exit);
复制代码
我输出的dest值一直都是69,source也不确定值,会改变?不知道问什么?是我tcp头地址读错了吗?谢谢
还有一个问题为什么在钩子函数中输出skb->data_len的值是0?
作者:
lanqiucoco
时间:
2012-04-30 15:28
额,那个printk("source port = %s\n",tcpth->source);打错了,是%d的。最后这个的值一直都是69,不管是什么包?求解,谢谢!
作者:
lanqiucoco
时间:
2012-04-30 23:00
额,没人理我
实验发现和以前的版本差不多...
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2