将多字节整数类型的数据,从主机的字节顺序转化为网络字节顺序

 

#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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2021-10-25
  • 2022-01-27
  • 2021-11-17
  • 2021-08-17
  • 2021-10-03
相关资源
相似解决方案