|
Description
The htonl(), htons(), ntohl() and ntohs() macros convert shorts and integers from host byte order to network byte order and vice versa.
The data type definitions in in_addr_t and in_port_t in <arpa/inet.h> correspond to the definitions in <netinet/in.h>.
These macros are used in conjunction with IPv4 addresses and port numbers, e.g. as returned by the gethostbyname() and getservent() functions. The macros are only needed on systems on which the host and network byte orders are different and are provided in the <arpa/inet.h> header file as null macros (macros without functions) for POSIX/BS2000:
htonl() converts 32 bit values from host to network byte order.
htons() converts 16 bit values from host to network byte order.
ntohl() converts 32 bit values from network to host byte order.
ntohs() converts 16 bit values from network to host byte order.
Return value
htonl() and htons() return the input parameter after conversion into network byte order.
ntohl() and ntohs() return the input parameter after conversion into host byte order.
See also
gethostbyaddr(), gethostbyname(), gethostent(), getservent()