network programming - Is ip_hdr() on a sk_buff guaranteed to work? -


when dealing sk_buff in kernel modules code, see many code samples use either

(struct iphdr *)skb_network_header(skb) //skb instance of (struct sk_buff*) 

or function ip_hdr() same (calling skb_network_header , casting). safe? if don't have assumptions on sk_buff came from, there check can make sure network protocol indeed ip?

edit: may point there can sk_buff possible network protocol ip, still see "proof" or explanation that. if implement own protocol in linux kernel example , network protocol header may else? how can make sure network transport protocol indeed ip?

skb refers socket buffer, data structures used represent , manage packets in linux kernel.
, implementation of linux network system designed independent of specific protocol.
socket buffer in linux kernel network system give more details.

to question:
caller called skb_network_header() should guarantee knows protocal. proof : can find out many references skb_network_header(), including arp_hdr(), ipv6_hdr(), ip_hdr(), etc. caller call arp_hdr() casting network header aprhdr, guarantee protocal arp.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -