C++ htons(), htonl(), ntohs(), ntohl()詳解

將多字節整數類型的數據,從主機的字節順序轉化爲網絡字節順序 網絡

#include <netinet/in.h> ui

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

htonl就是把本機字節順序轉化爲網絡字節順序。 內存

所謂網絡字節順序(大尾順序)就是指一個數在內存中存儲的時候「高對低,低對高」(即一個數的高位字節存放於低地址單元,低位字節存放在高地址單元中)。可是計算機的內存存儲數據時有多是大尾順序或者小尾順序。 數據

h---host 本地主機
to  就是to 了
n  ---net 網絡的意思
l 是 unsigned long
stl

"s"表示short,"l"表示long
hosts

相關文章
相關標籤/搜索