The htons function converts a u_short from host to TCP/IP network byte order (which is big-endian).
u_short htons(
u_short hostshort
)
hostshort
Type: u_shortÂ
[in]
A 16-bit number in host byte order.
Type: u_shortÂ
The htons function returns the value in TCP/IP network byte order.
The htons function takes a 16-bit number in host byte order and returns a 16-bit number in network byte order used in TCP/IP networks (the AF_INET or AF_INET6 address family).
The htons function can be used to convert an IP port number in host byte order to the IP port number in network byte order.
The htons function does not require that the Winsock DLL has previously been loaded with a successful call to the WSAStartup function.
(Microsoft Store apps): This API is supported.
Header: Declared in winsock2.h.
Library: Use ws2_32.lib.