]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - doc/html/ref/net-common-tcpip-manpages-byteorder.html
Initial revision
[karo-tx-redboot.git] / doc / html / ref / net-common-tcpip-manpages-byteorder.html
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.               -->
9 <HTML
10 ><HEAD
11 ><TITLE
12 >byteorder</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
14 <META
15 NAME="GENERATOR"
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
17 "><LINK
18 REL="HOME"
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
21 REL="UP"
22 TITLE="TCP/IP Library Reference"
23 HREF="tcpip-library-reference.html"><LINK
24 REL="PREVIOUS"
25 TITLE="gethostname"
26 HREF="net-common-tcpip-manpages-gethostname.html"><LINK
27 REL="NEXT"
28 TITLE="ethers"
29 HREF="net-common-tcpip-manpages-ethers.html"></HEAD
30 ><BODY
31 CLASS="SECT1"
32 BGCOLOR="#FFFFFF"
33 TEXT="#000000"
34 LINK="#0000FF"
35 VLINK="#840084"
36 ALINK="#0000FF"
37 ><DIV
38 CLASS="NAVHEADER"
39 ><TABLE
40 SUMMARY="Header navigation table"
41 WIDTH="100%"
42 BORDER="0"
43 CELLPADDING="0"
44 CELLSPACING="0"
45 ><TR
46 ><TH
47 COLSPAN="3"
48 ALIGN="center"
49 >eCos Reference Manual</TH
50 ></TR
51 ><TR
52 ><TD
53 WIDTH="10%"
54 ALIGN="left"
55 VALIGN="bottom"
56 ><A
57 HREF="net-common-tcpip-manpages-gethostname.html"
58 ACCESSKEY="P"
59 >Prev</A
60 ></TD
61 ><TD
62 WIDTH="80%"
63 ALIGN="center"
64 VALIGN="bottom"
65 >Chapter 38. TCP/IP Library Reference</TD
66 ><TD
67 WIDTH="10%"
68 ALIGN="right"
69 VALIGN="bottom"
70 ><A
71 HREF="net-common-tcpip-manpages-ethers.html"
72 ACCESSKEY="N"
73 >Next</A
74 ></TD
75 ></TR
76 ></TABLE
77 ><HR
78 ALIGN="LEFT"
79 WIDTH="100%"></DIV
80 ><DIV
81 CLASS="SECT1"
82 ><H1
83 CLASS="SECT1"
84 ><A
85 NAME="NET-COMMON-TCPIP-MANPAGES-BYTEORDER">byteorder</H1
86 ><TABLE
87 BORDER="5"
88 BGCOLOR="#E0E0F0"
89 WIDTH="70%"
90 ><TR
91 ><TD
92 ><PRE
93 CLASS="SCREEN"
94 >BYTEORDER(3)            System Library Functions Manual           BYTEORDER(3)
95
96 NAME
97      htonl, htons, ntohl, ntohs, htobe32, htobe16, betoh32, betoh16, htole32,
98      htole16, letoh32, letoh16, swap32, swap16 - convert values between dif-
99      ferent byte orderings
100
101 SYNOPSIS
102      #include &lt;sys/types.h&#62;
103      #include &lt;machine/endian.h&#62;
104
105      u_int32_t
106      htonl(u_int32_t host32);
107
108      u_int16_t
109      htons(u_int16_t host16);
110
111      u_int32_t
112      ntohl(u_int32_t net32);
113
114      u_int16_t
115      ntohs(u_int16_t net16);
116
117      u_int32_t
118      htobe32(u_int32_t host32);
119
120      u_int16_t
121      htobe16(u_int16_t host16);
122
123      u_int32_t
124      betoh32(u_int32_t big32);
125
126      u_int16_t
127      betoh16(u_int16_t big16);
128
129      u_int32_t
130      htole32(u_int32_t host32);
131
132      u_int16_t
133      htole16(u_int16_t host16);
134
135      u_int32_t
136      letoh32(u_int32_t little32);
137
138      u_int16_t
139      letoh16(u_int16_t little16);
140
141      u_int32_t
142      swap32(u_int32_t val32);
143
144      u_int16_t
145      swap16(u_int16_t val16);
146
147 DESCRIPTION
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.
152
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:
156
157            h    Host order.
158            n    Network order (big-endian).
159            be   Big-endian (most significant byte first).
160            le   Little-endian (least significant byte first).
161
162      One of the specified orderings must be `h'.  {size} will take these
163      forms:
164
165            l  Long (32-bit, used in conjunction with forms involving `n').
166            s  Short (16-bit, used in conjunction with forms involving `n').
167            16
168               16-bit.
169            32
170               32-bit.
171
172      The swap functions are of the form: swap{size}.
173
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.
180
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
185      macros.
186
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).
190
191 SEE ALSO
192      gethostbyname(3), getservent(3)
193
194 HISTORY
195      The byteorder functions appeared in 4.2BSD.
196
197 BUGS
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
200      in the near future.
201
202 BSD                              June 4, 1993                              BSD
203     </PRE
204 ></TD
205 ></TR
206 ></TABLE
207 ></DIV
208 ><DIV
209 CLASS="NAVFOOTER"
210 ><HR
211 ALIGN="LEFT"
212 WIDTH="100%"><TABLE
213 SUMMARY="Footer navigation table"
214 WIDTH="100%"
215 BORDER="0"
216 CELLPADDING="0"
217 CELLSPACING="0"
218 ><TR
219 ><TD
220 WIDTH="33%"
221 ALIGN="left"
222 VALIGN="top"
223 ><A
224 HREF="net-common-tcpip-manpages-gethostname.html"
225 ACCESSKEY="P"
226 >Prev</A
227 ></TD
228 ><TD
229 WIDTH="34%"
230 ALIGN="center"
231 VALIGN="top"
232 ><A
233 HREF="ecos-ref.html"
234 ACCESSKEY="H"
235 >Home</A
236 ></TD
237 ><TD
238 WIDTH="33%"
239 ALIGN="right"
240 VALIGN="top"
241 ><A
242 HREF="net-common-tcpip-manpages-ethers.html"
243 ACCESSKEY="N"
244 >Next</A
245 ></TD
246 ></TR
247 ><TR
248 ><TD
249 WIDTH="33%"
250 ALIGN="left"
251 VALIGN="top"
252 >gethostname</TD
253 ><TD
254 WIDTH="34%"
255 ALIGN="center"
256 VALIGN="top"
257 ><A
258 HREF="tcpip-library-reference.html"
259 ACCESSKEY="U"
260 >Up</A
261 ></TD
262 ><TD
263 WIDTH="33%"
264 ALIGN="right"
265 VALIGN="top"
266 >ethers</TD
267 ></TR
268 ></TABLE
269 ></DIV
270 ></BODY
271 ></HTML
272 >