在通过网络传输数据时约定统一方式为大端序
1.字节序间的转换
//h代表host主机字节序 n代表net网络字节序 s代表short l代表long
unsigned short htons(unsigned short);
unsigned short ntohs(unsigned short);
unsigned long htons(unsigned long);
unsigned long ntohs(unsigned long);
2.字符串与网络字节序间的转换
字符串转网络字节序
#include <arpa/inet.h>
//将点分十进制的字符串形式的IP地址转换为32位整型数据
in_addr_t inet_addr(const char *string);
#include <arpa/inet.h>
//将点分十进制的字符串形式的IP地址转换为32位整型数据并保存到结构体中
int inet_aton(const char *string, struct in_addr *addr);
网络字节序转字符串
#include <arpa/inet.h>
//将整形网络字节序转化成字符串形式
char * inet_ntoa(struct in_addr adr);