1. 程式人生 > >巧記:htonl、htons、ntohl、ntohs

巧記:htonl、htons、ntohl、ntohs

uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
具體作用如下:
The htonl() function converts the unsigned integer hostlong from host byte order to network byte order.
The htons() function converts the unsigned short integer hostshort from host byte order to network byte order.
The ntohl() function converts the unsigned integer netlong from network byte order to host byte order.
The ntohs() function converts the unsigned short integer netshort from network byte order to host byte order.
巧記:
h  → host
to → 轉換
n  → network
l  → long  我猜
s  → short