WSAHtons

The WSAHtons function converts a u_short from host byte order to network byte order.

Syntax

int WSAHtons(
         SOCKET s,
         u_short hostshort,
         u_short *lpnetshort
)  

Parameters

s
Type: SOCKET 

[in]

A descriptor identifying a socket.

hostshort
Type: u_short 

[in]

A 16-bit number in host byte order.

lpnetshort
Type: u_short *

[out]

A pointer to a 16-bit buffer to receive the number in network byte order.

Return value

Type: int 

If no error occurs, WSAHtons returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Return codes
Return code Description
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAENOTSOCK The descriptor is not a socket.
WSAEFAULT The lpnetshort parameter is NULL or the address pointed to is not completely contained in a valid part of the user address space.

Remarks

The WSAHtons function takes a 16-bit number in host byte order and returns a 16-bit number in network byte order in the 16-bit number pointed to by the lpnetshort parameter. The socket passed in the s parameter is used to determine the network byte order required based on the Winsock catalog protocol entry associated with the socket. This feature supports Winsock providers that use different network byte orders.

If the socket is for the AF_INET or AF_INET6 address family, the WSAHtons function can be used to convert an IP port number in host byte order to the IP port number in network byte order.

The WSAHtons function requires that the Winsock DLL has previously been loaded with a successful call to the WSAStartup function. For use with the AF_INET OR AF_INET6 address family, the htons function does not require that the Winsock DLL be loaded.

Windows Phone 8: This API is supported.

Requirements

Header: Declared in winsock2.h.

Library: Use ws2_32.lib.