htons(3) — Subroutines
NAME
htons - Converts an unsigned short (16-bit) integer from host byte order to a 2-byte Internet network integer
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <netinet/in.h> unsigned short htons (
unsigned short hostshort) ;
PARAMETERS
hostshortSpecifies a 16-bit integer in host byte order.
DESCRIPTION
The htons() (host-to-network short) function converts an unsigned short (16-bit) integer from host byte order to Internet network-byte order.
The Internet network requires address and port reference data in network-byte order (most significant byte leftmost, least significant byte rightmost). Use the htons() function to convert address and port short integers from host byte order to Internet network-byte order.
The htons() function is defined as a big-endian macro in the netinet/in.h header file for machine environments where network-byte order and host byte order are identical.
RETURN VALUES
Upon successful completion, the htons() function returns a 16-bit short integer in Internet network-byte order.