Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what kind of fields in network packets should be converted to network byte order

I know the endianess on hosts and network may be different but why the byte order is important?

I think there are two reasons:

1 for the router to check the ip header(likeaddresses), the routers only recognize big-endian order(network byte order) 2 for the receiving host to recognize the byte order of the packets. Since the receiving host doesn't know the byte order of the sending host, if the byte order is not converted to network byte order, it doesn't know the packet byte order.

am I right?

so for the following fields, which should be converted to byte order, and why?

1 TCP/UDP Header options, like MSS, timestamps
2 TCP/UDP header checksum
3 TCP sequence number
4 UDP/TCP data fields
like image 404
user138126 Avatar asked Oct 21 '22 14:10

user138126


1 Answers

Every field that is sent/stored as binary data (not ASCII, in particular) that is longer than a single byte needs to have a well-defined byte order. Otherwise, as you indicated, the receiver doesn't know how to interpret what the sender sent.

The answer to your specific question is that #1, #2, and #3 need to be in network byte order. As for the fields in the UDP/TCP payload (#4), that's up to you. Network byte order (big endian) is suggested, for consistency with almost every other protocol, but if you are defining a protocol then you can choose little endian if you want. Some have.

like image 51
Celada Avatar answered Oct 25 '22 18:10

Celada