当前位置: 技术问答>linux和unix
hook后获得的sk_buff指针为什么会是0?
来源: 互联网 发布时间:2016-10-06
本文导语: 代码如下: 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 iphdr* pIph = (struct iphdr *)skb_networ...
代码如下:
dmesg看到的内容是:
[ 5306.200961] minifw: accept, skb = 0x3519949824, sb=0x0
[ 5306.200978] minifw: accept, skb = 0x3519949824, sb=0x0
[ 5308.170271] minifw: accept, skb = 0x3519950592, sb=0x0
[ 5308.170277] minifw: accept, skb = 0x3519950592, sb=0x0
[ 5314.220847] minifw: accept, skb = 0x3519950400, sb=0x0
[ 5314.220855] minifw: accept, skb = 0x3519947520, sb=0x0
[ 5315.050048] minifw: accept, skb = 0x3718783360, sb=0x0
[ 5315.050065] minifw: accept, skb = 0x3519947520, sb=0x0
[ 5315.219833] minifw: accept, skb = 0x3519947520, sb=0x0
[ 5315.219841] minifw: accept, skb = 0x3519949440, sb=0x0
[ 5315.798450] minifw: accept, skb = 0x3718887872, sb=0x0
[ 5316.548244] minifw: accept, skb = 0x3718887872, sb=0x0
[ 5319.298713] minifw: accept, skb = 0x3718888640, sb=0x0
[ 5319.298731] minifw: accept, skb = 0x3718888640, sb=0x0
[ 5320.048327] minifw: accept, skb = 0x3718887296, sb=0x0
[ 5320.798252] minifw: accept, skb = 0x3718887296, sb=0x0
为什么sb是0呢?
内核是2.6.35的
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 iphdr* pIph = (struct iphdr *)skb_network_header(sb);
unsigned int srcIp = pIph->saddr;
unsigned int desIp = pIph->daddr;
unsigned int protocol = pIph->protocol;
//struct tcphdr* pTcph=(struct tcphdr*)(sb->data+(sb->nh.iph->ihl*4));
struct tcphdr* pTcph = (struct tcphdr *)skb_transport_header(sb);
unsigned int srcPort = pTcph->source;
unsigned int desPort = pTcph->dest;
printk("minifw: accept, skb = 0x%u, sb=0x%un",skb,*skb);
return NF_ACCEPT;
}
dmesg看到的内容是:
[ 5306.200961] minifw: accept, skb = 0x3519949824, sb=0x0
[ 5306.200978] minifw: accept, skb = 0x3519949824, sb=0x0
[ 5308.170271] minifw: accept, skb = 0x3519950592, sb=0x0
[ 5308.170277] minifw: accept, skb = 0x3519950592, sb=0x0
[ 5314.220847] minifw: accept, skb = 0x3519950400, sb=0x0
[ 5314.220855] minifw: accept, skb = 0x3519947520, sb=0x0
[ 5315.050048] minifw: accept, skb = 0x3718783360, sb=0x0
[ 5315.050065] minifw: accept, skb = 0x3519947520, sb=0x0
[ 5315.219833] minifw: accept, skb = 0x3519947520, sb=0x0
[ 5315.219841] minifw: accept, skb = 0x3519949440, sb=0x0
[ 5315.798450] minifw: accept, skb = 0x3718887872, sb=0x0
[ 5316.548244] minifw: accept, skb = 0x3718887872, sb=0x0
[ 5319.298713] minifw: accept, skb = 0x3718888640, sb=0x0
[ 5319.298731] minifw: accept, skb = 0x3718888640, sb=0x0
[ 5320.048327] minifw: accept, skb = 0x3718887296, sb=0x0
[ 5320.798252] minifw: accept, skb = 0x3718887296, sb=0x0
为什么sb是0呢?
内核是2.6.35的
|
新的kernel里面hook函数的原型已经改过了:
typedef unsigned int nf_hookfn(unsigned int hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *));
typedef unsigned int nf_hookfn(unsigned int hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *));
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。