htonl 函数 (winsock2.h)

htonl 函数将u_long从主机转换为 TCP/IP 网络字节顺序 (这是 big-endian) 。

语法

u_long WSAAPI htonl(
  [in] u_long hostlong
);

参数

[in] hostlong

主机字节顺序中的 32 位数字。

返回值

htonl 函数以 TCP/IP 的网络字节顺序返回值。

注解

htonl 函数采用主机字节顺序的 32 位数字,并在 TCP/IP 网络中使用的网络字节顺序中返回一个 32 位数字, (AF_INET或AF_INET6地址系列) 。

htonl 函数可用于将主机字节顺序中的 IPv4 地址转换为网络字节顺序中的 IPv4 地址。 此函数不会执行任何检查来确定 hostlong 参数是否为有效的 IPv4 地址。

htonl 函数不要求之前已通过成功调用 WSAStartup 函数加载 Winsock DLL。

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
标头 winsock2.h (包括 Winsock2.h)
Library Ws2_32.lib
DLL Ws2_32.dll

另请参阅

InetNtop

InetPton

WSAHtonl

WSAHtons

WSANtohl

WSANtohs

htond

htonf

htonll

htons

inet_addr

inet_ntoa

ntohd

ntohf

ntohll

ntohs