OpenBSD manual page server

Manual Page Search Parameters

HTONL(3) Library Functions Manual HTONL(3)

htonl, htons, ntohl, ntohsconvert values between host and network byte orderings

#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);

These routines convert 16 and 32-bit quantities between different byte orderings.

The () and () functions convert quantities from host to network byte order while the () and () 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).

gethostbyname(3), getservent(3)

The htonl(), htons(), ntohl(), and ntohs() functions conform to IEEE Std 1003.1 (“POSIX.1”).

These functions appeared in 4.2BSD.

On the vax, 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.

September 4, 2014 OpenBSD-5.9