htons()

C++ htons(), htonl(), ntohs(), ntohl()详解

。_饼干妹妹 提交于 2019-12-07 20:44:42
将多字节整数类型的数据,从主机的字节顺序转化为网络字节顺序 #include <netinet/in.h> uint32_t htonl(uint32_t hostlong); uint16_t htons(uint16_t hostshort); uint32_t ntohl(uint32_t netlong); uint16_t ntohs(uint16_t netshort); htonl就是把本机字节顺序转化为网络字节顺序。 所谓网络字节顺序(大尾顺序)就是指一个数在内存中存储的时候“高对低,低对高”(即一个数的高位字节存放于低地址单元,低位字节存放在高地址单元中)。但是计算机的内存存储数据时有可能是大尾顺序或者小尾顺序。 h---host 本地主机 to 就是to 了 n ---net 网络的意思 l 是 unsigned long "s"表示short,"l"表示long 来源: oschina 链接: https://my.oschina.net/u/200838/blog/181901