htonl、htons头文件

  1. 在linux的头文件
 #include <arpa/inet.h>
  1. 在windows的头文件
#include <windows.h>
#pragma comment(lib, "wsock32.lib")

来自:https://zhidao.baidu.com/question/166926781.html

(亲测,只用如下的库也可行)

#include<WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
  1. 意思
    htonl()–“Host to Network Long”
    ntohl()–“Network to Host Long”
    htons()–“Host to Network Short”
    ntohs()–“Network to Host Short”

uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);

记忆这类函数,主要看前面的n和后面的hl。。n代表网络,h代表主机host,l代表long的长度,还有相对应的s代表16位的short
同类的函数:ntohs()、htons() 就是转成short类型的。
原文:https://blog.csdn.net/andrewgithub/article/details/81638236

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章