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.3107
1 files changed, 66 insertions, 41 deletions
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3
index aa11b22664..64a13d47ba 100644
--- a/src/lib/libc/net/byteorder.3
+++ b/src/lib/libc/net/byteorder.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: byteorder.3,v 1.6 1999/05/23 14:11:01 aaron Exp $ 1.\" $OpenBSD: byteorder.3,v 1.7 1999/07/05 04:40:59 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.
@@ -82,56 +82,86 @@
82.Ft u_int16_t 82.Ft u_int16_t
83.Fn swap16 "u_int16_t val16" 83.Fn swap16 "u_int16_t val16"
84.Sh DESCRIPTION 84.Sh DESCRIPTION
85These routines convert 16 and 32 bit quantities between different 85These routines convert 16- and 32-bit quantities between different
86byte orderings. The "swap" functions reverse the byte ordering of 86byte orderings. The
87.Dq swap
88functions reverse the byte ordering of
87the given quantity, the others converts either from/to the native 89the given quantity, the others converts either from/to the native
88byte order used by the host to/from either little- or big-endian (a.k.a 90byte order used by the host to/from either little- or big-endian (a.k.a
89network) order. 91network) order.
90.Pp 92.Pp
91Apart from the "swap" functions, the names can be described by this form: 93Apart from the swap functions, the names can be described by this form:
92{src-order}to{dst-order}{size}. 94{src-order}to{dst-order}{size}.
93Both {src-order} and {dst-order} can take the following forms: 95Both {src-order} and {dst-order} can take the following forms:
94.Bl -tag -width "be " 96.Pp
95.It Em h 97.Bl -tag -width "be " -offset indent -compact
96host order 98.It h
97.It Em n 99Host order.
98network order (big-endian) 100.It n
99.It Em be 101Network order (big-endian).
100big-endian (Most significant byte first) 102.It be
101.It Em le 103Big-endian (most significant byte first).
102little-endian (Least significant byte first) 104.It le
105Little-endian (least significant byte first).
103.El 106.El
104.Pp 107.Pp
105One of the specified orderings must be "h". 108One of the specified orderings must be
106{Size} will take these forms: 109.Sq h .
107.Bl -tag -width "32 " 110{size} will take these forms:
108.It Em l 111.Pp
109long (32-bit, used in conjunction with forms involving "n") 112.Bl -tag -width "32 " -offset indent -compact
110.It Em s 113.It l
111short (16-bit, used in conjunction with forms involving "n") 114Long (32-bit, used in conjunction with forms involving
112.It Em 16 115.Sq n ) .
11316-bit 116.It s
114.It Em 32 117Short (16-bit, used in conjunction with forms involving
11532-bit 118.Sq n ) .
119.It 16
12016-bit.
121.It 32
12232-bit.
116.El 123.El
117.Pp 124.Pp
118The "swap" functions are of the form: swap{size}. 125The swap functions are of the form: swap{size}.
119.Pp 126.Pp
120Names involving "n" convert quantities between network 127Names involving
121byte order and host byte order. The last letter (s/l) is a mnemonic 128.Sq n
122for the traditional names for such quantities, short and long, 129convert quantities between network
123respectively. Today, the C concept of "short"/"long" integers 130byte order and host byte order. The last letter
124need not coincide with this traditional misunderstanding. 131.Pf ( Sq s
132or
133.Sq l )
134is a mnemonic
135for the traditional names for such quantities,
136.Li short
137and
138.Li long ,
139respectively. Today, the C concept of
140.Li short
141and
142.Li long
143integers need not coincide with this traditional misunderstanding.
125On machines which have a byte order which is the same as the network 144On machines which have a byte order which is the same as the network
126order, routines are defined as null macros. 145order, routines are defined as null macros.
127.Pp 146.Pp
128The functions involving either "be", "le" or "swap" use the numbers 147The functions involving either
129(16/32) for specifying the bitwidth of the quantities they operate on. 148.Dq be ,
149.Dq le ,
150or
151.Dq swap
152use the numbers
15316 and 32 for specifying the bitwidth of the quantities they operate on.
130Currently all supported architectures are either big- or little-endian 154Currently all supported architectures are either big- or little-endian
131so either the "be" or the "le" variants are implemented as null macros. 155so either the
156.Dq be
157or
158.Dq le
159variants are implemented as null macros.
132.Pp 160.Pp
133The routines mentioned above which have either {src-order} or {dst-order} 161The routines mentioned above which have either {src-order} or {dst-order}
134set to "n" are most often used in 162set to
163.Sq n
164are most often used in
135conjunction with Internet addresses and ports as returned by 165conjunction with Internet addresses and ports as returned by
136.Xr gethostbyname 3 166.Xr gethostbyname 3
137and 167and
@@ -142,14 +172,9 @@ and
142.Sh HISTORY 172.Sh HISTORY
143The 173The
144.Nm byteorder 174.Nm byteorder
145functions appeared in 175functions appeared in
146.Bx 4.2 . 176.Bx 4.2 .
147.Sh BUGS 177.Sh BUGS
148On the 178On the vax, alpha, i386, and so far mips,
149.Tn vax ,
150.Tn alpha ,
151.Tn i386 ,
152and so far
153.Tn mips
154bytes are handled backwards from most everyone else in 179bytes are handled backwards from most everyone else in
155the world. This is not expected to be fixed in the near future. 180the world. This is not expected to be fixed in the near future.