*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->OpenBSD man pages -> byteorder (3)              
Title
Content
Arch
Section
 

BYTEORDER(3)

Contents


NAME    [Toc]    [Back]

     htonl,  htons,  ntohl,  ntohs,  htobe64,  htobe32,  htobe16,
betoh64, betoh32,
     betoh16,   htole64,   htole32,  htole16,  letoh64,  letoh32,
letoh16, swap64,
     swap32, swap16 - convert values between different  byte  orderings

SYNOPSIS    [Toc]    [Back]

     #include <sys/types.h>

     u_int32_t
     htonl(u_int32_t host32);

     u_int16_t
     htons(u_int16_t host16);

     u_int32_t
     ntohl(u_int32_t net32);

     u_int16_t
     ntohs(u_int16_t net16);

     u_int64_t
     htobe64(u_int64_t host64);

     u_int32_t
     htobe32(u_int32_t host32);

     u_int16_t
     htobe16(u_int16_t host16);

     u_int64_t
     betoh64(u_int64_t big64);

     u_int32_t
     betoh32(u_int32_t big32);

     u_int16_t
     betoh16(u_int16_t big16);

     u_int64_t
     htole64(u_int64_t host64);

     u_int32_t
     htole32(u_int32_t host32);

     u_int16_t
     htole16(u_int16_t host16);

     u_int64_t
     letoh64(u_int64_t little64);

     u_int32_t
     letoh32(u_int32_t little32);

     u_int16_t
     letoh16(u_int16_t little16);

     u_int64_t
     swap64(u_int32_t val64);

     u_int32_t
     swap32(u_int32_t val32);

     u_int16_t
     swap16(u_int16_t val16);

DESCRIPTION    [Toc]    [Back]

     These  routines convert 16, 32 and 64-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  {dstorder} 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.
           64   64-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 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.

     The functions involving either ``be'', ``le'',  or  ``swap''
use the numbers
  16, 32 and 64 for specifying the bitwidth of the quantities they operate
 on.  Currently all supported architectures are  either
big- or little-endian
  so  either the ``be'' or ``le'' variants are implemented as
     null macros.

     The routines mentioned above which have  either  {src-order}
or {dst-order}
     set  to `n' are most often used in conjunction with Internet
addresses and
     ports as returned by gethostbyname(3) and getservent(3).

SEE ALSO    [Toc]    [Back]

      
      
     gethostbyname(3), getservent(3)

STANDARDS    [Toc]    [Back]

     The htonl(), htons(), ntohl(), and ntohs() functions conform
to IEEE Std
     1003.1 (``POSIX'').  The other functions are extensions that
should not
     be used when portability is required.

HISTORY    [Toc]    [Back]

     The byteorder functions appeared in 4.2BSD.

BUGS    [Toc]    [Back]

     On the vax, alpha, i386, and some mips architectures,  bytes
are handled
     backwards from most everyone else in the world.  This is not
expected to
     be fixed in the near future.

OpenBSD      3.6                           June      4,      1993
[ Back ]
 Similar pages
Name OS Title
byteorder Linux convert values between host and network byte order
htonl FreeBSD convert values between host and network byte order
htons FreeBSD convert values between host and network byte order
ntohl FreeBSD convert values between host and network byte order
ntohs FreeBSD convert values between host and network byte order
byteorder IRIX convert values between host and network byte order
ntohs NetBSD convert values between host and network byte order
byteorder NetBSD convert values between host and network byte order
byteorder FreeBSD convert values between host and network byte order
htonl NetBSD convert values between host and network byte order
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service