ntohs
ntohs, short for network-to-host short, is a function or macro used in network programming to convert 16-bit values from network byte order to the host machine’s native byte order. Network byte order is defined as big-endian, meaning the most significant byte is transmitted first. The host machine’s byte order may be little-endian or big-endian; ntohs adapts the value to the host’s order by swapping bytes on little-endian systems and leaving it unchanged on big-endian systems.
On POSIX systems, ntohs is declared in arpa/inet.h, and on Windows it is provided in WinSock2.h. The
ntohs is commonly used when interpreting protocol headers where 16-bit fields are transmitted in network order,
Related functions include htons (host-to-network short) for converting from host order to network order, and ntohl /