Comtrol eCos User Manual
Page 510

Chapter 38. TCP/IP Library Reference
u_int32_t
htole32(u_int32_t host32);
u_int16_t
htole16(u_int16_t host16);
u_int32_t
letoh32(u_int32_t little32);
u_int16_t
letoh16(u_int16_t little16);
u_int32_t
swap32(u_int32_t val32);
u_int16_t
swap16(u_int16_t val16);
DESCRIPTION
These routines convert 16- and 32-bit quantities between different byte
orderings.
The “swap” functions reverse the byte ordering of the given
quantity, the others converts either from/to the native byte order used
by the host to/from either little- or big-endian (a.k.a network) order.
Apart from the swap functions, the names can be described by this form:
{src-order}to{dst-order}{size}.
Both {src-order} and {dst-order} can
take the following forms:
h
Host order.
n
Network order (big-endian).
be
Big-endian (most significant byte first).
le
Little-endian (least significant byte first).
One of the specified orderings must be ‘h’.
{size} will take these
forms:
l
Long (32-bit, used in conjunction with forms involving ‘n’).
s
Short (16-bit, used in conjunction with forms involving ‘n’).
16
16-bit.
32
32-bit.
The swap functions are of the form: swap{size}.
Names involving ‘n’ convert quantities between network byte order and
host byte order.
The last letter (‘s’ or ‘l’) is a mnemonic for the tra-
ditional names for such quantities, short and long, respectively.
Today,
the C concept of short and long integers need not coincide with this tra-
ditional misunderstanding.
On machines which have a byte order which is
the same as the network order, routines are defined as null macros.
The functions involving either “be”, “le”, or “swap” use the num-
bers 16 and 32 for specifying the bitwidth of the quantities they operate
on.
Currently all supported architectures are either big- or little-
406