侧边栏壁纸
博主头像
noerror

虚灵不寐,众理具而万事出。

  • 累计撰写 239 篇文章
  • 累计创建 9 个标签
  • 累计收到 2 条评论
标签搜索

目 录CONTENT

文章目录

byteorder函数用法详解

noerror
2022-10-04 / 0 评论 / 0 点赞 / 112 阅读 / 251 字 / 正在检测是否收录...

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上使用的网络字节顺序是最高有效字节优先。

0

评论区