NAME
htonl
, htons
,
ntohl
, ntohs
—
convert values between host and network
byte orderings
SYNOPSIS
#include
<arpa/inet.h>
uint32_t
htonl
(uint32_t
host32);
uint16_t
htons
(uint16_t
host16);
uint32_t
ntohl
(uint32_t
net32);
uint16_t
ntohs
(uint16_t
net16);
DESCRIPTION
These routines convert 16 and 32-bit quantities between different byte orderings.The
htonl
() and
htons
()
functions convert quantities from host to network byte order while the
ntohl
()
and
ntohs
()
functions convert in the other direction.
The last letter (‘s’ or ‘l’) is a
mnemonic for the traditional names for such quantities,
short
and long
,
respectively. Today, the C concept of short
and
long
integers need not coincide with this
traditional misunderstanding. On machines which have a byte order which is
the same as the network order, routines are defined as null macros.
These routines are most often used in conjunction with Internet addresses and ports as returned by gethostbyname(3) and getservent(3).
SEE ALSO
STANDARDS
The htonl
(),
htons
(), ntohl
(), and
ntohs
() functions conform to IEEE
Std 1003.1 (“POSIX.1”).
HISTORY
These functions appeared in 4.2BSD.
BUGS
On the alpha, amd64, i386, and some mips and arm architectures, bytes are handled backwards from most everyone else in the world. This is not expected to be fixed in the near future.