我试图将从机器输出的所有数据包的源IP修改为我在这个内核模块中指定的内容,但是每次我尝试访问nh.iph->时,都会在编译时得到一个错误,即Struct sk_buff没有名为nh的成员。
我在这里做错什么了?我是不是漏了头球什么的??
#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;
}请注意,我正在运行Ubuntu10.04LTS 64位
内核2.6.32-33
发布于 2012-04-05 08:29:23
在您的内核版本中,struct sk_buff已经更改。它不再有那些成员了。要访问ip报头,您应该尝试:
#include <linux/ip.h>
struct iphdr* iph = ip_hdr(skb);然后只需使用iph变量更改地址,如下所示:
iph->saddr = ....
iph->daddr = ....此外,不要忘记,您可能需要重新计算ip和可能的传输数据包校验和。
发布于 2012-04-05 08:30:13
您可以在'include/linux/skbuff.h‘中找到sk_buff的定义。
它没有nh字段,这解释了您正在看到的编译错误。它确实有一个“network_header”字段,这可能就是你想要的。
https://stackoverflow.com/questions/10025026
复制相似问题