网络数据包中的哪些字段应转换为网络字节顺序 [英] what kind of fields in network packets should be converted to network byte order

查看:134
本文介绍了网络数据包中的哪些字段应转换为网络字节顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道主机和网络的随机性可能有所不同 但是为什么字节顺序很重要?

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

我认为有两个原因:

1用于路由器检查ip标头(likeaddresses),路由器仅识别大端顺序(网络字节顺序) 2,以便接收主机识别数据包的字节顺序.由于接收主机不知道发送主机的字节顺序,因此如果字节顺序未转换为网络字节顺序,则它也不知道数据包字节顺序.

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.

我说得对吗?

对于以下字段,应将其转换为字节顺序,为什么?

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

推荐答案

每个以二进制数据(特别是非ASCII)发送/存储的字段(其长度大于单个字节)必须具有明确定义的字节顺序.否则,正如您所指出的,接收者不知道如何解释发送者发送的内容.

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.

您的特定问题的答案是#1,#2和#3必须采用网络字节顺序.至于UDP/TCP有效负载(#4)中的字段,则取决于您.建议使用网络字节顺序(大字节序),以便与几乎所有其他协议保持一致,但是如果要定义协议,则可以选择小字节序.有些有.

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.

这篇关于网络数据包中的哪些字段应转换为网络字节顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆