由于本机存储数据字节的顺序和网络传输的数据字节顺序不同,需要进行字节顺序的转化函数,linux提供了以下四个函数:
#include <arpa/inet.h>
uint32_t htonl(uint32_t hostint32);
返回:32位的network byte order
uin16_t htons(uint16_t hostint16);
返回:16位的network byte order
uint32_t ntohl(uint32_t netint32);
返回:32位的host byte order
uint16_t ntohs(uint16_t netint16);
返回:16位的host byte order
n代表network
h代表host
l代表long
s代表short