|
|
求助: 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;
} |
|