加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C – 无法访问saddr

发布时间:2020-12-16 07:28:59 所属栏目:百科 来源:网络整理
导读:我试图用netfilter钩子处理简单的数据包检查. 宣言似乎相当简单: 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 iphdr *iph = (str
我试图用netfilter钩子处理简单的数据包检查.

宣言似乎相当简单:

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 iphdr *iph = (struct iphdr *)skb_network_header(skb);

}

我可以访问网络标头的协议部分

iph-> protocol == IPPROTO_TCP

然而

iph-> SADDR

失败.有什么建议?我觉得这对我来说是一个相当简单的错误,但所有的例子都遵循这种方法或者他们只是使用

struct iphdr * iph = ip_hdr(skb);

我对这两种方法都有相同的行为.我查看了skbuff.h的任何线索,但没有任何运气.

编辑:

这可能与我访问它的方式有关吗?现在进行调试我只是尝试使用以下方法打印出值:

printk(KERN_DEBUG“%pI4”,iph-> saddr);

解决方法

%pI4占用一个地址,因此您正在读取可能无效的内存.请改用& iph-> saddr.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读