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

北城以北 提交于 2019-12-23 14:20:07

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/15526598/what-kind-of-fields-in-network-packets-should-be-converted-to-network-byte-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!