网络字节序:在网络协议中用于表示多字节整数的统一字节排列方式,通常指 大端序(big-endian),即高位字节在前、低位字节在后。常用于 TCP/IP 等协议以及套接字编程中(如 htons/htonl 与 ntohs/ntohl 的转换)。
/ˈnɛtˌwɝk baɪt ˈɔɹdɚ/
The port number must be in network byte order.
端口号必须使用网络字节序。
Before sending the packet, the program converts the 32-bit length field to network byte order to ensure it is interpreted correctly across different CPU architectures.
在发送数据包之前,程序将 32 位长度字段转换为网络字节序,以确保在不同 CPU 架构上都能被正确解析。
该术语由三部分组成:network(网络)+ byte(字节)+ order(顺序/排列)。随着互联网协议的发展,为了让不同硬件平台(可能使用不同端序,如小端序或大端序)之间能够一致地解释数据字段,TCP/IP 体系将“网络上传输的标准字节顺序”固定为大端序,并称为 network byte order。