htonl function

The htonl function converts a u_long from host to TCP/IP network byte order (which is big-endian).

Syntax

u_long htonl(
  u_long hostlong
);

Parameters

hostlong

A 32-bit number in host byte order.

Return Value

The htonl function returns the value in TCP/IP's network byte order.

Remarks

The htonl function takes a 32-bit number in host byte order and returns a 32-bit number in the network byte order used in TCP/IP networks (the AF_INET or AF_INET6 address family).

The htonl function can be used to convert an IPv4 address in host byte order to the IPv4 address in network byte order. This function does not do any checking to determine if the hostlong parameter is a valid IPv4 address.

The htonlfunction does not require that the Winsock DLL has previously been loaded with a successful call to the WSAStartup function.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

Requirements

   
Windows version Windows 8.1, Windows Vista [desktop apps | UWP apps] Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header winsock.h (include Winsock2.h)
Library Ws2_32.lib
DLL Ws2_32.dll

See Also

InetNtop

InetPton

WSAHtonl

WSAHtons

WSANtohl

WSANtohs

htond

htonf

htonll

htons

inet_addr

inet_ntoa

ntohd

ntohf

ntohll

ntohs