ip_hdr vs ipip_hdr

Ricky zhangchaowang at gmail.com
Thu Aug 18 04:47:25 EDT 2016


In include/linux/ip.h, 

23 static inline struct iphdr *ip_hdr(const struct sk_buff *skb)
24 {
25         return (struct iphdr *)skb_network_header(skb);
26 }
27 
28 static inline struct iphdr *inner_ip_hdr(const struct sk_buff *skb)
29 {
30         return (struct iphdr *)skb_inner_network_header(skb);
31 }
32 
33 static inline struct iphdr *ipip_hdr(const struct sk_buff *skb)
34 {
35         return (struct iphdr *)skb_transport_header(skb);
36 }
37 #endif  /* _LINUX_IP_H */
if I passed in sk_buff to ip_hdr and ipip_hdr

struct iphdr *ip_hdr ip_hdr_net = ip_hdr(skb);
struct iphdr *ip_hdr ip_hdr_trans = ipip_hdr(skb);
Do ip_hdr_net->saddr and ip_hdr_trans->saddr point to the same thing? I tried it on code. It doesn't. It seems that only ip_hdr_net->saddr point to source IP address, which make sense. Because network layer has IP but not on transport layer.

So questions:

(1) what is differences between ip_hdr and ipip_hdr? Why we have them? No documentation whatever to figure it out.

(2) should I use ntohX function to convert ip_hdr member data when accessing them? eg, ip_hdr_net->saddr.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160818/92982c0e/attachment-0001.html 


More information about the Kernelnewbies mailing list