Fin*_*fin 4 kernel-module linux-kernel
我想修改从机器上的所有数据包outcoming的东西我在这个内核模块指定的源IP,但每次我尝试访问nh.iph-> SADDR我得到一个错误的编译时间,上面写着结构sk_buff中没有成员这个名字叫
什么我在做错了什么?我错过了一些标题还是什么?
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/skbuff.h>
#include <linux/ip.h> /* For IP header */
#include <linux/inet.h> /* For in_aton(); htonl(); and other related Network utility functions */
static struct nf_hook_ops nfho;
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 in_addr masterIP;
masterIP.s_addr = htonl (in_aton("192.168.1.10"));
sb->nh.iph->saddr = masterIP.s_addr;
return NF_ACCEPT;
}
Run Code Online (Sandbox Code Playgroud)
请注意,我正在运行Ubuntu 10.04 LTS 64位
内核2.6.32-33
Fre*_*red 13
在你的内核版本中,它struct sk_buff已经改变了.它不再拥有这些成员.要访问ip标头,您应该尝试:
#include <linux/ip.h>
struct iphdr* iph = ip_hdr(skb);
Run Code Online (Sandbox Code Playgroud)
然后只需使用iph变量来更改地址,例如:
iph->saddr = ....
iph->daddr = ....
Run Code Online (Sandbox Code Playgroud)
另外,不要忘记您可能需要重新计算ip和可能的传输数据包校验和.