summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/byteorder.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/byteorder.3')
-rw-r--r--src/lib/libc/net/byteorder.3151
1 files changed, 128 insertions, 23 deletions
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3
index 701a69f688..9d8fa7221f 100644
--- a/src/lib/libc/net/byteorder.3
+++ b/src/lib/libc/net/byteorder.3
@@ -1,4 +1,4 @@
1.\" $NetBSD: byteorder.3,v 1.3 1995/02/25 06:20:27 cgd Exp $ 1.\" $OpenBSD: byteorder.3,v 1.8 2000/04/18 03:01:30 aaron Exp $
2.\" 2.\"
3.\" Copyright (c) 1983, 1991, 1993 3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
@@ -31,35 +31,141 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
33.\" 33.\"
34.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993 34.Dd June 4, 1993
37.Dt BYTEORDER 3 35.Dt BYTEORDER 3
38.Os BSD 4.2 36.Os
39.Sh NAME 37.Sh NAME
40.Nm htonl , 38.Nm htonl ,
41.Nm htons , 39.Nm htons ,
42.Nm ntohl , 40.Nm ntohl ,
43.Nm ntohs 41.Nm ntohs ,
44.Nd convert values between host and network byte order 42.Nm htobe32 ,
43.Nm htobe16 ,
44.Nm betoh32 ,
45.Nm betoh16 ,
46.Nm htole32 ,
47.Nm htole16 ,
48.Nm letoh32 ,
49.Nm letoh16 ,
50.Nm swap32 ,
51.Nm swap16
52.Nd convert values between different byte orderings
45.Sh SYNOPSIS 53.Sh SYNOPSIS
46.Fd #include <sys/param.h> 54.Fd #include <sys/types.h>
47.Ft u_long 55.Fd #include <machine/endian.h>
48.Fn htonl "u_long hostlong" 56.Ft u_int32_t
49.Ft u_short 57.Fn htonl "u_int32_t host32"
50.Fn htons "u_short hostshort" 58.Ft u_int16_t
51.Ft u_long 59.Fn htons "u_int16_t host16"
52.Fn ntohl "u_long netlong" 60.Ft u_int32_t
53.Ft u_short 61.Fn ntohl "u_int32_t net32"
54.Fn ntohs "u_short netshort" 62.Ft u_int16_t
63.Fn ntohs "u_int16_t net16"
64.Ft u_int32_t
65.Fn htobe32 "u_int32_t host32"
66.Ft u_int16_t
67.Fn htobe16 "u_int16_t host16"
68.Ft u_int32_t
69.Fn betoh32 "u_int32_t big32"
70.Ft u_int16_t
71.Fn betoh16 "u_int16_t big16"
72.Ft u_int32_t
73.Fn htole32 "u_int32_t host32"
74.Ft u_int16_t
75.Fn htole16 "u_int16_t host16"
76.Ft u_int32_t
77.Fn letoh32 "u_int32_t little32"
78.Ft u_int16_t
79.Fn letoh16 "u_int16_t little16"
80.Ft u_int32_t
81.Fn swap32 "u_int32_t val32"
82.Ft u_int16_t
83.Fn swap16 "u_int16_t val16"
55.Sh DESCRIPTION 84.Sh DESCRIPTION
56These routines convert 16 and 32 bit quantities between network 85These routines convert 16- and 32-bit quantities between different
86byte orderings.
87The
88.Dq swap
89functions reverse the byte ordering of
90the given quantity, the others converts either from/to the native
91byte order used by the host to/from either little- or big-endian (a.k.a
92network) order.
93.Pp
94Apart from the swap functions, the names can be described by this form:
95{src-order}to{dst-order}{size}.
96Both {src-order} and {dst-order} can take the following forms:
97.Pp
98.Bl -tag -width "be " -offset indent -compact
99.It h
100Host order.
101.It n
102Network order (big-endian).
103.It be
104Big-endian (most significant byte first).
105.It le
106Little-endian (least significant byte first).
107.El
108.Pp
109One of the specified orderings must be
110.Sq h .
111{size} will take these forms:
112.Pp
113.Bl -tag -width "32 " -offset indent -compact
114.It l
115Long (32-bit, used in conjunction with forms involving
116.Sq n ) .
117.It s
118Short (16-bit, used in conjunction with forms involving
119.Sq n ) .
120.It 16
12116-bit.
122.It 32
12332-bit.
124.El
125.Pp
126The swap functions are of the form: swap{size}.
127.Pp
128Names involving
129.Sq n
130convert quantities between network
57byte order and host byte order. 131byte order and host byte order.
132The last letter
133.Pf ( Sq s
134or
135.Sq l )
136is a mnemonic
137for the traditional names for such quantities,
138.Li short
139and
140.Li long ,
141respectively.
142Today, the C concept of
143.Li short
144and
145.Li long
146integers need not coincide with this traditional misunderstanding.
58On machines which have a byte order which is the same as the network 147On machines which have a byte order which is the same as the network
59order, routines are defined as null macros. 148order, routines are defined as null macros.
60.Pp 149.Pp
61These routines are most often used in conjunction with Internet 150The functions involving either
62addresses and ports as returned by 151.Dq be ,
152.Dq le ,
153or
154.Dq swap
155use the numbers
15616 and 32 for specifying the bitwidth of the quantities they operate on.
157Currently all supported architectures are either big- or little-endian
158so either the
159.Dq be
160or
161.Dq le
162variants are implemented as null macros.
163.Pp
164The routines mentioned above which have either {src-order} or {dst-order}
165set to
166.Sq n
167are most often used in
168conjunction with Internet addresses and ports as returned by
63.Xr gethostbyname 3 169.Xr gethostbyname 3
64and 170and
65.Xr getservent 3 . 171.Xr getservent 3 .
@@ -69,10 +175,9 @@ and
69.Sh HISTORY 175.Sh HISTORY
70The 176The
71.Nm byteorder 177.Nm byteorder
72functions appeared in 178functions appeared in
73.Bx 4.2 . 179.Bx 4.2 .
74.Sh BUGS 180.Sh BUGS
75On the 181On the vax, alpha, i386, and so far mips,
76.Tn VAX 182bytes are handled backwards from most everyone else in the world.
77bytes are handled backwards from most everyone else in 183This is not expected to be fixed in the near future.
78the world. This is not expected to be fixed in the near future.