<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>byteorder</TITLE
|
>byteorder</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="TCP/IP Library Reference"
|
TITLE="TCP/IP Library Reference"
|
HREF="tcpip-library-reference.html"><LINK
|
HREF="tcpip-library-reference.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="gethostname"
|
TITLE="gethostname"
|
HREF="net-common-tcpip-manpages-gethostname.html"><LINK
|
HREF="net-common-tcpip-manpages-gethostname.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="ethers"
|
TITLE="ethers"
|
HREF="net-common-tcpip-manpages-ethers.html"></HEAD
|
HREF="net-common-tcpip-manpages-ethers.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="SECT1"
|
CLASS="SECT1"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-gethostname.html"
|
HREF="net-common-tcpip-manpages-gethostname.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
>Chapter 38. TCP/IP Library Reference</TD
|
>Chapter 38. TCP/IP Library Reference</TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-ethers.html"
|
HREF="net-common-tcpip-manpages-ethers.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="NET-COMMON-TCPIP-MANPAGES-BYTEORDER">byteorder</H1
|
NAME="NET-COMMON-TCPIP-MANPAGES-BYTEORDER">byteorder</H1
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>BYTEORDER(3) System Library Functions Manual BYTEORDER(3)
|
>BYTEORDER(3) System Library Functions Manual BYTEORDER(3)
|
|
|
NAME
|
NAME
|
htonl, htons, ntohl, ntohs, htobe32, htobe16, betoh32, betoh16, htole32,
|
htonl, htons, ntohl, ntohs, htobe32, htobe16, betoh32, betoh16, htole32,
|
htole16, letoh32, letoh16, swap32, swap16 - convert values between dif-
|
htole16, letoh32, letoh16, swap32, swap16 - convert values between dif-
|
ferent byte orderings
|
ferent byte orderings
|
|
|
SYNOPSIS
|
SYNOPSIS
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <machine/endian.h>
|
#include <machine/endian.h>
|
|
|
u_int32_t
|
u_int32_t
|
htonl(u_int32_t host32);
|
htonl(u_int32_t host32);
|
|
|
u_int16_t
|
u_int16_t
|
htons(u_int16_t host16);
|
htons(u_int16_t host16);
|
|
|
u_int32_t
|
u_int32_t
|
ntohl(u_int32_t net32);
|
ntohl(u_int32_t net32);
|
|
|
u_int16_t
|
u_int16_t
|
ntohs(u_int16_t net16);
|
ntohs(u_int16_t net16);
|
|
|
u_int32_t
|
u_int32_t
|
htobe32(u_int32_t host32);
|
htobe32(u_int32_t host32);
|
|
|
u_int16_t
|
u_int16_t
|
htobe16(u_int16_t host16);
|
htobe16(u_int16_t host16);
|
|
|
u_int32_t
|
u_int32_t
|
betoh32(u_int32_t big32);
|
betoh32(u_int32_t big32);
|
|
|
u_int16_t
|
u_int16_t
|
betoh16(u_int16_t big16);
|
betoh16(u_int16_t big16);
|
|
|
u_int32_t
|
u_int32_t
|
htole32(u_int32_t host32);
|
htole32(u_int32_t host32);
|
|
|
u_int16_t
|
u_int16_t
|
htole16(u_int16_t host16);
|
htole16(u_int16_t host16);
|
|
|
u_int32_t
|
u_int32_t
|
letoh32(u_int32_t little32);
|
letoh32(u_int32_t little32);
|
|
|
u_int16_t
|
u_int16_t
|
letoh16(u_int16_t little16);
|
letoh16(u_int16_t little16);
|
|
|
u_int32_t
|
u_int32_t
|
swap32(u_int32_t val32);
|
swap32(u_int32_t val32);
|
|
|
u_int16_t
|
u_int16_t
|
swap16(u_int16_t val16);
|
swap16(u_int16_t val16);
|
|
|
DESCRIPTION
|
DESCRIPTION
|
These routines convert 16- and 32-bit quantities between different byte
|
These routines convert 16- and 32-bit quantities between different byte
|
orderings. The ``swap'' functions reverse the byte ordering of the given
|
orderings. The ``swap'' functions reverse the byte ordering of the given
|
quantity, the others converts either from/to the native byte order used
|
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.
|
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:
|
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
|
{src-order}to{dst-order}{size}. Both {src-order} and {dst-order} can
|
take the following forms:
|
take the following forms:
|
|
|
h Host order.
|
h Host order.
|
n Network order (big-endian).
|
n Network order (big-endian).
|
be Big-endian (most significant byte first).
|
be Big-endian (most significant byte first).
|
le Little-endian (least significant byte first).
|
le Little-endian (least significant byte first).
|
|
|
One of the specified orderings must be `h'. {size} will take these
|
One of the specified orderings must be `h'. {size} will take these
|
forms:
|
forms:
|
|
|
l Long (32-bit, used in conjunction with forms involving `n').
|
l Long (32-bit, used in conjunction with forms involving `n').
|
s Short (16-bit, used in conjunction with forms involving `n').
|
s Short (16-bit, used in conjunction with forms involving `n').
|
16
|
16
|
16-bit.
|
16-bit.
|
32
|
32
|
32-bit.
|
32-bit.
|
|
|
The swap functions are of the form: swap{size}.
|
The swap functions are of the form: swap{size}.
|
|
|
Names involving `n' convert quantities between network byte order and
|
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-
|
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,
|
ditional names for such quantities, short and long, respectively. Today,
|
the C concept of short and long integers need not coincide with this tra-
|
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
|
ditional misunderstanding. On machines which have a byte order which is
|
the same as the network order, routines are defined as null macros.
|
the same as the network order, routines are defined as null macros.
|
|
|
The functions involving either ``be'', ``le'', or ``swap'' use the num-
|
The functions involving either ``be'', ``le'', or ``swap'' use the num-
|
bers 16 and 32 for specifying the bitwidth of the quantities they operate
|
bers 16 and 32 for specifying the bitwidth of the quantities they operate
|
on. Currently all supported architectures are either big- or little-
|
on. Currently all supported architectures are either big- or little-
|
endian so either the ``be'' or ``le'' variants are implemented as null
|
endian so either the ``be'' or ``le'' variants are implemented as null
|
macros.
|
macros.
|
|
|
The routines mentioned above which have either {src-order} or {dst-order}
|
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
|
set to `n' are most often used in conjunction with Internet addresses and
|
ports as returned by gethostbyname(3) and getservent(3).
|
ports as returned by gethostbyname(3) and getservent(3).
|
|
|
SEE ALSO
|
SEE ALSO
|
gethostbyname(3), getservent(3)
|
gethostbyname(3), getservent(3)
|
|
|
HISTORY
|
HISTORY
|
The byteorder functions appeared in 4.2BSD.
|
The byteorder functions appeared in 4.2BSD.
|
|
|
BUGS
|
BUGS
|
On the vax, alpha, i386, and so far mips, bytes are handled backwards
|
On the vax, alpha, i386, and so far mips, bytes are handled backwards
|
from most everyone else in the world. This is not expected to be fixed
|
from most everyone else in the world. This is not expected to be fixed
|
in the near future.
|
in the near future.
|
|
|
BSD June 4, 1993 BSD
|
BSD June 4, 1993 BSD
|
</PRE
|
</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-gethostname.html"
|
HREF="net-common-tcpip-manpages-gethostname.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-ethers.html"
|
HREF="net-common-tcpip-manpages-ethers.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>gethostname</TD
|
>gethostname</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>ethers</TD
|
>ethers</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|