summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguenther <>2014-07-13 13:17:16 +0000
committerguenther <>2014-07-13 13:17:16 +0000
commita507f9dd9387923514b8801e5f4424765bf792d1 (patch)
treef3f49da34e32740ce4214ca6ee7a426c4c3e6608
parent798d3e3b70b7fb466e6bca59ceb18b2c4e92658d (diff)
downloadopenbsd-a507f9dd9387923514b8801e5f4424765bf792d1.tar.gz
openbsd-a507f9dd9387923514b8801e5f4424765bf792d1.tar.bz2
openbsd-a507f9dd9387923514b8801e5f4424765bf792d1.zip
Split out ntoh[ls] and hton[ls] into their own manpage.
Update byteorder(3) to cover the new functions in <endian.h> ok deraadt@ millert@
-rw-r--r--src/lib/libc/net/Makefile.inc19
-rw-r--r--src/lib/libc/net/byteorder.3212
-rw-r--r--src/lib/libc/net/htonl.3104
3 files changed, 199 insertions, 136 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc
index b3acad72bf..6b427174d8 100644
--- a/src/lib/libc/net/Makefile.inc
+++ b/src/lib/libc/net/Makefile.inc
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile.inc,v 1.54 2014/06/11 16:59:47 chrisz Exp $ 1# $OpenBSD: Makefile.inc,v 1.55 2014/07/13 13:17:16 guenther Exp $
2 2
3# net sources 3# net sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net
@@ -27,18 +27,18 @@ SRCS+= ip6opt.c rthdr.c vars6.c
27 27
28MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ 28MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \
29 getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ 29 getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \
30 getrrsetbyname.3 getservent.3 if_indextoname.3 \ 30 getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \
31 inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ 31 inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \
32 inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ 32 inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \
33 rcmd.3 rcmdsh.3 resolver.3 33 rcmd.3 rcmdsh.3 resolver.3
34 34
35MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ 35MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \
36 byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \ 36 byteorder.3 be16toh.3 byteorder.3 be32toh.3 byteorder.3 be64toh.3 \
37 byteorder.3 htobe64.3 byteorder.3 betoh16.3 byteorder.3 betoh32.3 \ 37 byteorder.3 betoh16.3 byteorder.3 betoh32.3 byteorder.3 betoh64.3 \
38 byteorder.3 betoh64.3 byteorder.3 htole16.3 byteorder.3 htole32.3 \ 38 byteorder.3 htole16.3 byteorder.3 htole32.3 byteorder.3 htole64.3 \
39 byteorder.3 htole64.3 byteorder.3 letoh16.3 byteorder.3 letoh32.3 \ 39 byteorder.3 le16toh.3 byteorder.3 le32toh.3 byteorder.3 le64toh.3 \
40 byteorder.3 letoh64.3 byteorder.3 swap16.3 byteorder.3 swap32.3 \ 40 byteorder.3 letoh16.3 byteorder.3 letoh32.3 byteorder.3 letoh64.3 \
41 byteorder.3 swap64.3 41 byteorder.3 swap16.3 byteorder.3 swap32.3 byteorder.3 swap64.3
42MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ 42MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \
43 ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 43 ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3
44MLINKS+=getaddrinfo.3 freeaddrinfo.3 44MLINKS+=getaddrinfo.3 freeaddrinfo.3
@@ -59,6 +59,7 @@ MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \
59 getservent.3 getservent_r.3 getservent.3 getservbyname_r.3 \ 59 getservent.3 getservent_r.3 getservent.3 getservbyname_r.3 \
60 getservent.3 getservbyport_r.3 getservent.3 setservent_r.3 \ 60 getservent.3 getservbyport_r.3 getservent.3 setservent_r.3 \
61 getservent.3 endservent_r.3 61 getservent.3 endservent_r.3
62MLINKS+=htonl.3 htons.3 htonl.3 ntohl.3 htonl.3 ntohs.3
62MLINKS+= if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ 63MLINKS+= if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \
63 if_indextoname.3 if_freenameindex.3 64 if_indextoname.3 if_freenameindex.3
64MLINKS+=inet_addr.3 inet_aton.3 inet_addr.3 inet_network.3 \ 65MLINKS+=inet_addr.3 inet_aton.3 inet_addr.3 inet_network.3 \
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3
index 53f9fd071d..921c8343fa 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.18 2013/06/05 03:39:22 tedu Exp $ 1.\" $OpenBSD: byteorder.3,v 1.19 2014/07/13 13:17:16 guenther 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.
@@ -27,23 +27,25 @@
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.Dd $Mdocdate: June 5 2013 $ 30.Dd $Mdocdate: July 13 2014 $
31.Dt BYTEORDER 3 31.Dt BYTEORDER 3
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm htonl ,
35.Nm htons ,
36.Nm ntohl ,
37.Nm ntohs ,
38.Nm htobe64 , 34.Nm htobe64 ,
39.Nm htobe32 , 35.Nm htobe32 ,
40.Nm htobe16 , 36.Nm htobe16 ,
37.Nm be64toh ,
38.Nm be32toh ,
39.Nm be16toh ,
41.Nm betoh64 , 40.Nm betoh64 ,
42.Nm betoh32 , 41.Nm betoh32 ,
43.Nm betoh16 , 42.Nm betoh16 ,
44.Nm htole64 , 43.Nm htole64 ,
45.Nm htole32 , 44.Nm htole32 ,
46.Nm htole16 , 45.Nm htole16 ,
46.Nm le64toh ,
47.Nm le32toh ,
48.Nm le16toh ,
47.Nm letoh64 , 49.Nm letoh64 ,
48.Nm letoh32 , 50.Nm letoh32 ,
49.Nm letoh16 , 51.Nm letoh16 ,
@@ -52,45 +54,49 @@
52.Nm swap16 54.Nm swap16
53.Nd convert values between different byte orderings 55.Nd convert values between different byte orderings
54.Sh SYNOPSIS 56.Sh SYNOPSIS
55.In sys/types.h 57.In endian.h
56.Ft u_int32_t 58.Ft uint64_t
57.Fn htonl "u_int32_t host32" 59.Fn htobe64 "uint64_t host64"
58.Ft u_int16_t 60.Ft uint32_t
59.Fn htons "u_int16_t host16" 61.Fn htobe32 "uint32_t host32"
60.Ft u_int32_t 62.Ft uint16_t
61.Fn ntohl "u_int32_t net32" 63.Fn htobe16 "uint16_t host16"
62.Ft u_int16_t 64.Ft uint64_t
63.Fn ntohs "u_int16_t net16" 65.Fn be64toh "uint64_t big64"
64.Ft u_int64_t 66.Ft uint32_t
65.Fn htobe64 "u_int64_t host64" 67.Fn be32toh "uint32_t big32"
66.Ft u_int32_t 68.Ft uint16_t
67.Fn htobe32 "u_int32_t host32" 69.Fn be16toh "uint16_t big16"
68.Ft u_int16_t 70.Ft uint64_t
69.Fn htobe16 "u_int16_t host16" 71.Fn betoh64 "uint64_t big64"
70.Ft u_int64_t 72.Ft uint32_t
71.Fn betoh64 "u_int64_t big64" 73.Fn betoh32 "uint32_t big32"
72.Ft u_int32_t 74.Ft uint16_t
73.Fn betoh32 "u_int32_t big32" 75.Fn betoh16 "uint16_t big16"
74.Ft u_int16_t 76.Ft uint64_t
75.Fn betoh16 "u_int16_t big16" 77.Fn htole64 "uint64_t host64"
76.Ft u_int64_t 78.Ft uint32_t
77.Fn htole64 "u_int64_t host64" 79.Fn htole32 "uint32_t host32"
78.Ft u_int32_t 80.Ft uint16_t
79.Fn htole32 "u_int32_t host32" 81.Fn htole16 "uint16_t host16"
80.Ft u_int16_t 82.Ft uint64_t
81.Fn htole16 "u_int16_t host16" 83.Fn letoh64 "uint64_t little64"
82.Ft u_int64_t 84.Ft uint64_t
83.Fn letoh64 "u_int64_t little64" 85.Fn le64toh "uint64_t little64"
84.Ft u_int32_t 86.Ft uint32_t
85.Fn letoh32 "u_int32_t little32" 87.Fn le32toh "uint32_t little32"
86.Ft u_int16_t 88.Ft uint16_t
87.Fn letoh16 "u_int16_t little16" 89.Fn le16toh "uint16_t little16"
88.Ft u_int64_t 90.Ft uint32_t
89.Fn swap64 "u_int64_t val64" 91.Fn letoh32 "uint32_t little32"
90.Ft u_int32_t 92.Ft uint16_t
91.Fn swap32 "u_int32_t val32" 93.Fn letoh16 "uint16_t little16"
92.Ft u_int16_t 94.Ft uint64_t
93.Fn swap16 "u_int16_t val16" 95.Fn swap64 "uint64_t val64"
96.Ft uint32_t
97.Fn swap32 "uint32_t val32"
98.Ft uint16_t
99.Fn swap16 "uint16_t val16"
94.Sh DESCRIPTION 100.Sh DESCRIPTION
95These routines convert 16, 32 and 64-bit quantities between different 101These routines convert 16, 32 and 64-bit quantities between different
96byte orderings. 102byte orderings.
@@ -101,70 +107,16 @@ the given quantity; the others convert either from/to the native
101byte order used by the host to/from either little- or big-endian (a.k.a 107byte order used by the host to/from either little- or big-endian (a.k.a
102network) order. 108network) order.
103.Pp 109.Pp
104Apart from the swap functions, the names can be described by this form: 110Apart from the swap functions,
105{src-order}to{dst-order}{size}. 111the names containing
106Both {src-order} and {dst-order} can take the following forms: 112.Dq be
107.Pp 113convert between host and big-endian (most significant byte first) order
108.Bl -tag -width "be " -offset indent -compact 114of the given quantity, while the names containing
109.It h 115.Dq le
110Host order. 116convert between host and little-endian least significant byte first) order
111.It n 117of the given quantity.
112Network order (big-endian).
113.It be
114Big-endian (most significant byte first).
115.It le
116Little-endian (least significant byte first).
117.El
118.Pp
119One of the specified orderings must be
120.Sq h .
121{size} will take these forms:
122.Pp
123.Bl -tag -width "32 " -offset indent -compact
124.It l
125Long (32-bit, used in conjunction with forms involving
126.Sq n ) .
127.It s
128Short (16-bit, used in conjunction with forms involving
129.Sq n ) .
130.It 16
13116-bit.
132.It 32
13332-bit.
134.It 64
13564-bit.
136.El
137.Pp
138The swap functions are of the form: swap{size}.
139.Pp
140Names involving
141.Sq n
142convert quantities between network
143byte order and host byte order.
144The last letter
145.Pf ( Sq s
146or
147.Sq l )
148is a mnemonic
149for the traditional names for such quantities,
150.Li short
151and
152.Li long ,
153respectively.
154Today, the C concept of
155.Li short
156and
157.Li long
158integers need not coincide with this traditional misunderstanding.
159On machines which have a byte order which is the same as the network
160order, routines are defined as null macros.
161.Pp 118.Pp
162The functions involving either 119All these functions use the numbers
163.Dq be ,
164.Dq le ,
165or
166.Dq swap
167use the numbers
16816, 32, or 64 for specifying the bitwidth of the quantities they operate on. 12016, 32, or 64 for specifying the bitwidth of the quantities they operate on.
169Currently all supported architectures are either big- or little-endian 121Currently all supported architectures are either big- or little-endian
170so either the 122so either the
@@ -172,34 +124,40 @@ so either the
172or 124or
173.Dq le 125.Dq le
174variants are implemented as null macros. 126variants are implemented as null macros.
175.Pp
176The routines mentioned above which have either {src-order} or {dst-order}
177set to
178.Sq n
179are most often used in
180conjunction with Internet addresses and ports as returned by
181.Xr gethostbyname 3
182and
183.Xr getservent 3 .
184.Sh SEE ALSO 127.Sh SEE ALSO
185.Xr gethostbyname 3 , 128.Xr htonl 3
186.Xr getservent 3
187.Sh STANDARDS 129.Sh STANDARDS
188The 130The
189.Fn htonl , 131.Fn htobe64 ,
190.Fn htons , 132.Fn htobe32 ,
191.Fn ntohl , 133.Fn htobe16 ,
134.Fn be64toh ,
135.Fn be32toh ,
136.Fn be16toh ,
137.Fn htole64 ,
138.Fn htole32 ,
139.Fn htole16 ,
140.Fn le64toh ,
141.Fn le32toh ,
192and 142and
193.Fn ntohs 143.Fn le16toh
194functions conform to 144functions are expected to conform to a future version of
195.St -p1003.1 . 145.St -p1003.1 .
196The other functions are extensions that should not be used when portability 146The other functions are extensions that should not be used
197is required. 147when portability is required.
198.Sh HISTORY 148.Sh HISTORY
199The 149The
200.Nm byteorder 150.Nm swap{size}
151and
152.Nm {src-order}to{dst-order}{size}
201functions appeared in 153functions appeared in
202.Bx 4.2 . 154.Bx 4.2 .
155The
156.Nm {src-order}{size}to{dst-order}
157functions appeared in
158.Ox 5.6 .
159A subset of them was submitted for standardization after
160.St -p1003.1-2008 .
203.Sh BUGS 161.Sh BUGS
204On the vax, alpha, amd64, i386, and some mips and arm architectures, 162On the vax, alpha, amd64, i386, and some mips and arm architectures,
205bytes are handled backwards from most everyone else in the world. 163bytes are handled backwards from most everyone else in the world.
diff --git a/src/lib/libc/net/htonl.3 b/src/lib/libc/net/htonl.3
new file mode 100644
index 0000000000..fdc84cb64c
--- /dev/null
+++ b/src/lib/libc/net/htonl.3
@@ -0,0 +1,104 @@
1.\" $OpenBSD: htonl.3,v 1.1 2014/07/13 13:17:16 guenther Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd $Mdocdate: July 13 2014 $
31.Dt HTONL 3
32.Os
33.Sh NAME
34.Nm htonl ,
35.Nm htons ,
36.Nm ntohl ,
37.Nm ntohs
38.Nd convert values between host and network byte orderings
39.Sh SYNOPSIS
40.In netinet/in.h
41.Ft uint32_t
42.Fn htonl "uint32_t host32"
43.Ft uint16_t
44.Fn htons "uint16_t host16"
45.Ft uint32_t
46.Fn ntohl "uint32_t net32"
47.Ft uint16_t
48.Fn ntohs "uint16_t net16"
49.Sh DESCRIPTION
50These routines convert 16 and 32-bit quantities between different
51byte orderings.
52.Pp
53The
54.Fn htonl
55and
56.Fn htons
57functions convert quantities from host to network byte order while the
58.Fn ntohl
59and
60.Fn ntohs
61functions convert the other direction.
62.Pp
63The last letter
64.Pf ( Sq s
65or
66.Sq l )
67is a mnemonic
68for the traditional names for such quantities,
69.Li short
70and
71.Li long ,
72respectively.
73Today, the C concept of
74.Li short
75and
76.Li long
77integers need not coincide with this traditional misunderstanding.
78On machines which have a byte order which is the same as the network
79order, routines are defined as null macros.
80.Pp
81These routines are most often used in conjunction with Internet
82addresses and ports as returned by
83.Xr gethostbyname 3
84and
85.Xr getservent 3 .
86.Sh SEE ALSO
87.Xr gethostbyname 3 ,
88.Xr getservent 3
89.Sh STANDARDS
90The
91.Fn htonl ,
92.Fn htons ,
93.Fn ntohl ,
94and
95.Fn ntohs
96functions conform to
97.St -p1003.1 .
98.Sh HISTORY
99These functions appeared in
100.Bx 4.2 .
101.Sh BUGS
102On the vax, alpha, amd64, i386, and some mips and arm architectures,
103bytes are handled backwards from most everyone else in the world.
104This is not expected to be fixed in the near future.