LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 571|回复: 0

求助: hook函数设置ttl值的问题

[复制链接]
发表于 2006-6-6 23:23:37 | 显示全部楼层 |阅读模式
求助: hook函数设置ttl值的问题

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


我编写了一个hook函数。实现了对ip数据报的修改。编译成模块,加载,抓包,都行。
但有两个问题:
(1) ttl的值虽然能改变,但是不是我预想的值。
如下面程序中我设置为:0x3f 本来认为为63。但是它出来为48
(2)我只在NF_IP_PRE_ROUTING注册了此函数。即只对进入的包进行ttl值改变。但是实际中它却是对所有的包进行了ttl值修改。
请问以上是什么原因造成的。请帮帮我。
代码见下:

#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

static struct nf_hook_ops nfho;

static unsigned char *drop_ip = "0x3f";

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;
sb->nh.iph->ttl=*(unsigned int *)drop_ip;
return NF_ACCEPT;

}

int init_module()
{

nfho.hook = hook_func;
nfho.hooknum = NF_IP_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;

nf_register_hook(&nfho);

return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表