byteorder函数用法详解
byteorder函数简介
- 头文件包含
#include <arpa/inet.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 );
byteorder函数常见使用错误
- 编译错误
warning: implicit declaration of function ‘byteorder’ [-Wimplicit-function-declaration]
解决办法:包含头文件
#include <arpa/inet.h>
byteorder函数详细描述
htonl ()函数将无符号整数hostlong从主机字节顺序转换为网络字节顺序。
htons ()函数将无符号短整数hostshort从主机字节顺序转换为网络字节顺序。
ntohl ()函数将无符号整数netlong从网络字节顺序转换为主机字节顺序。
ntohs ()函数将无符号短整数netshort从网络字节顺序转换为主机字节顺序。
在i386上,主机字节顺序是最低有效字节优先,而在Internet上使用的网络字节顺序是最高有效字节优先。
评论区