1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="TCP/IP Library Reference"
23 HREF="tcpip-library-reference.html"><LINK
26 HREF="net-common-tcpip-manpages-gethostname.html"><LINK
29 HREF="net-common-tcpip-manpages-ethers.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="net-common-tcpip-manpages-gethostname.html"
65 >Chapter 38. TCP/IP Library Reference</TD
71 HREF="net-common-tcpip-manpages-ethers.html"
85 NAME="NET-COMMON-TCPIP-MANPAGES-BYTEORDER">byteorder</H1
94 >BYTEORDER(3) System Library Functions Manual BYTEORDER(3)
97 htonl, htons, ntohl, ntohs, htobe32, htobe16, betoh32, betoh16, htole32,
98 htole16, letoh32, letoh16, swap32, swap16 - convert values between dif-
102 #include <sys/types.h>
103 #include <machine/endian.h>
106 htonl(u_int32_t host32);
109 htons(u_int16_t host16);
112 ntohl(u_int32_t net32);
115 ntohs(u_int16_t net16);
118 htobe32(u_int32_t host32);
121 htobe16(u_int16_t host16);
124 betoh32(u_int32_t big32);
127 betoh16(u_int16_t big16);
130 htole32(u_int32_t host32);
133 htole16(u_int16_t host16);
136 letoh32(u_int32_t little32);
139 letoh16(u_int16_t little16);
142 swap32(u_int32_t val32);
145 swap16(u_int16_t val16);
148 These routines convert 16- and 32-bit quantities between different byte
149 orderings. The ``swap'' functions reverse the byte ordering of the given
150 quantity, the others converts either from/to the native byte order used
151 by the host to/from either little- or big-endian (a.k.a network) order.
153 Apart from the swap functions, the names can be described by this form:
154 {src-order}to{dst-order}{size}. Both {src-order} and {dst-order} can
155 take the following forms:
158 n Network order (big-endian).
159 be Big-endian (most significant byte first).
160 le Little-endian (least significant byte first).
162 One of the specified orderings must be `h'. {size} will take these
165 l Long (32-bit, used in conjunction with forms involving `n').
166 s Short (16-bit, used in conjunction with forms involving `n').
172 The swap functions are of the form: swap{size}.
174 Names involving `n' convert quantities between network byte order and
175 host byte order. The last letter (`s' or `l') is a mnemonic for the tra-
176 ditional names for such quantities, short and long, respectively. Today,
177 the C concept of short and long integers need not coincide with this tra-
178 ditional misunderstanding. On machines which have a byte order which is
179 the same as the network order, routines are defined as null macros.
181 The functions involving either ``be'', ``le'', or ``swap'' use the num-
182 bers 16 and 32 for specifying the bitwidth of the quantities they operate
183 on. Currently all supported architectures are either big- or little-
184 endian so either the ``be'' or ``le'' variants are implemented as null
187 The routines mentioned above which have either {src-order} or {dst-order}
188 set to `n' are most often used in conjunction with Internet addresses and
189 ports as returned by gethostbyname(3) and getservent(3).
192 gethostbyname(3), getservent(3)
195 The byteorder functions appeared in 4.2BSD.
198 On the vax, alpha, i386, and so far mips, bytes are handled backwards
199 from most everyone else in the world. This is not expected to be fixed
213 SUMMARY="Footer navigation table"
224 HREF="net-common-tcpip-manpages-gethostname.html"
242 HREF="net-common-tcpip-manpages-ethers.html"
258 HREF="tcpip-library-reference.html"