Skip to content

Instantly share code, notes, and snippets.

@zhangzhiqiangcs
Last active March 13, 2017 07:23
Show Gist options
  • Save zhangzhiqiangcs/860b7a8636898e7339e68bc760ec5e6b to your computer and use it in GitHub Desktop.
Save zhangzhiqiangcs/860b7a8636898e7339e68bc760ec5e6b to your computer and use it in GitHub Desktop.
存放平时查阅资料需要记录下来的东西
网络字节顺序是TCP/IP中规定好的一种数据表示格式,它与具体的CPU类型、操作系统等无关,从而可以保证数据在不同主机之间传输时能够被正确解释。网络字节顺序采用big endian排序方式。
为了进行转换 bsd socket提供了转换的函数 有下面四个
htons 把unsigned short类型从主机序转换到网络序
htonl 把unsigned long类型从主机序转换到网络序
ntohs 把unsigned short类型从网络序转换到主机序
ntohl 把unsigned long类型从网络序转换到主机序
在使用little endian的系统中 这些函数会把字节序进行转换
在使用big endian类型的系统中 这些函数会定义成空宏
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment