C - 无法访问 Saddr
我正在尝试使用 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);
I am trying to handle simple packet inspection with netfilter hooks.
Declaration seems fairly straightforward:
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);
}
And I can access the protocol portion of the network header
iph->protocol == IPPROTO_TCP
However
iph->saddr
Fails. Any suggestions? I feel as this is a fairly simple error on my part, but all the examples follow either this method or they simply use
struct iphdr *iph = ip_hdr(skb);
I get the same behavior with both methods. I have looked through skbuff.h for any clues but havn't had any luck.
EDIT:
Could this have to do with they way I am accessing it? Right now for debugging I am merely trying to print the value out using:
printk(KERN_DEBUG "%pI4", iph->saddr);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
%pI4
采用一个地址,因此您正在读取可能无效的内存。请改用&iph->saddr
。%pI4
takes an address, so you are reading possibly invalid memory. Use&iph->saddr
instead.