htons 函式 (winsock.h)

htons 函式會將u_short從主機轉換成 TCP/IP 網路位元組順序 (,這是大端) 。

語法

u_short htons(
  [in] u_short hostshort
);

參數

[in] hostshort

以主機位元組順序表示的16位數位。

傳回值

htons 函式會以 TCP/IP 網路位元組順序傳回值。

備註

htons 函式會採用主機位元組順序的16位數位,並以TCP/IP網路所使用的網路位元組順序傳回16位數位, (AF_INET 或AF_INET6位址系列) 。

htons 函式可用來將主機位元組順序中的IP埠號碼轉換為網路位元組順序中的IP埠號碼。

htons 函式不需要先前已載入 Winsock DLL 並成功呼叫 WSAStartup 函式。

Windows 8.1Windows Server 2012 R2:Windows 8.1、Windows Server 2012 R2 及更新版本上的 Windows 市集應用程式支援此函式。

規格需求

需求
最低支援的用戶端 Windows 8.1、Windows Vista [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2003 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 winsock.h (包含 Winsock2.h)
程式庫 Ws2_32.lib
Dll Ws2_32.dll

另請參閱

InetNtop

InetPton

WSAHtonl

WSAHtons

WSANtohl

WSANtohs

htond

htonf

htonl

htonll

inet_addr

inet_ntoa

ntohd

ntohf

ntohl

ntohll

ntohs