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

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