Network byte order 指网络协议中规定的多字节数据(如 16 位、32 位整数)在传输时的字节排列顺序,通常为大端序(big-endian):高位字节在前、低位字节在后。常见于 IP、TCP、UDP 等协议字段,以及 C 语言套接字编程中的 htons/htonl 与 ntohs/ntohl 转换。(也有人把它简称为 NBO。)
/ˈnɛtˌwɝːk baɪt ˈɔːrdər/
The port number is sent in network byte order.
端口号会以网络字节序发送。
When parsing the TCP header, convert the 32-bit sequence number from network byte order to host byte order before doing arithmetic on it.
解析 TCP 首部时,应先把 32 位序列号从网络字节序转换为主机字节序,再对其进行运算。
该术语由 network(网络)+ byte(字节)+ order(顺序)组成。早期互联网协议为了在不同硬件架构(大小端不同)之间保持一致,规定传输采用统一的字节序;最终在主流协议与标准文档中固定为大端序,并被称为 “network byte order”。