summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniklas <>1997-11-19 23:30:18 +0000
committerniklas <>1997-11-19 23:30:18 +0000
commitfcae3f0133bf43582b77144daf5dfc07716863f3 (patch)
tree9566677017de07195f32d641d62b30fb7f167985
parentc15a85a1a1f4f97b26328bc947a6e647e2f42dca (diff)
downloadopenbsd-fcae3f0133bf43582b77144daf5dfc07716863f3.tar.gz
openbsd-fcae3f0133bf43582b77144daf5dfc07716863f3.tar.bz2
openbsd-fcae3f0133bf43582b77144daf5dfc07716863f3.zip
Document new functions
-rw-r--r--src/lib/libc/net/Makefile.inc7
-rw-r--r--src/lib/libc/net/byteorder.392
2 files changed, 87 insertions, 12 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc
index 4382cc6755..4bf4583914 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.13 1997/07/28 16:27:16 niklas Exp $ 1# $OpenBSD: Makefile.inc,v 1.14 1997/11/19 23:30:18 niklas Exp $
2 2
3# net sources 3# net sources
4.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/net ${.CURDIR}/net 4.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/net ${.CURDIR}/net
@@ -26,7 +26,10 @@ MAN+= byteorder.3 ethers.3 gethostbyname.3 getnetent.3 getprotoent.3 \
26 rcmd.3 rcmdsh.3 resolver.3 26 rcmd.3 rcmdsh.3 resolver.3
27 27
28MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ 28MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \
29 byteorder.3 ntohs.3 29 byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \
30 byteorder.3 betoh16.3 byteorder.3 betoh32.3 byteorder.3 htole16.3 \
31 byteorder.3 htole32.3 byteorder.3 letoh16.3 byteorder.3 letoh32.3 \
32 swap16.3 swap32.3
30MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ 33MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \
31 ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 34 ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3
32MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ 35MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3
index 53528df7e6..f2788b25dc 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.4 1997/04/05 21:13:05 millert Exp $ 1.\" $OpenBSD: byteorder.3,v 1.5 1997/11/19 23:30:17 niklas 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.
@@ -38,8 +38,18 @@
38.Nm htonl , 38.Nm htonl ,
39.Nm htons , 39.Nm htons ,
40.Nm ntohl , 40.Nm ntohl ,
41.Nm ntohs 41.Nm ntohs ,
42.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
43.Sh SYNOPSIS 53.Sh SYNOPSIS
44.Fd #include <sys/types.h> 54.Fd #include <sys/types.h>
45.Fd #include <machine/endian.h> 55.Fd #include <machine/endian.h>
@@ -51,8 +61,63 @@
51.Fn ntohl "u_int32_t net32" 61.Fn ntohl "u_int32_t net32"
52.Ft u_int16_t 62.Ft u_int16_t
53.Fn ntohs "u_int16_t net16" 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"
54.Sh DESCRIPTION 84.Sh DESCRIPTION
55These routines convert 16 and 32 bit quantities between network 85These routines convert 16 and 32 bit quantities between different
86byte orderings. The "swap" functions reverse the byte ordering of
87the 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
89network) order.
90.Pp
91Apart from the "swap" functions, the names can be described by this form:
92{src-order}to{dst-order}{size}.
93Both {src-order} and {dst-order} can take the following forms:
94.Bl -tag -width "be "
95.It Em h
96host order
97.It Em n
98network order (big-endian)
99.It Em be
100big-endian (Most significant byte first)
101.It Em le
102little-endian (Least significant byte first)
103.El
104.Pp
105One of the specified orderings must be "h".
106{Size} will take these forms:
107.Bl -tag -width "32 "
108.It Em l
109long (32-bit, used in conjunction with forms involving "n")
110.It Em s
111short (16-bit, used in conjunction with forms involving "n")
112.It Em 16
11316-bit
114.It Em 32
11532-bit
116.El
117.Pp
118The "swap" functions are of the form: swap{size}.
119.Pp
120Names involving "n" convert quantities between network
56byte order and host byte order. The last letter (s/l) is a mnemonic 121byte order and host byte order. The last letter (s/l) is a mnemonic
57for the traditional names for such quantities, short and long, 122for the traditional names for such quantities, short and long,
58respectively. Today, the C concept of "short"/"long" integers 123respectively. Today, the C concept of "short"/"long" integers
@@ -60,8 +125,14 @@ need not coincide with this traditional misunderstanding.
60On machines which have a byte order which is the same as the network 125On machines which have a byte order which is the same as the network
61order, routines are defined as null macros. 126order, routines are defined as null macros.
62.Pp 127.Pp
63These routines are most often used in conjunction with Internet 128The functions involving either "be", "le" or "swap" use the numbers
64addresses and ports as returned by 129(16/32) for specifying the bitwidth of the quantities they operate on.
130Currently all supported architectures are either big- or little-endian
131so either the "be" or the "le" variants are implemented as null macros.
132.Pp
133The routines mentioned above which have either {src-order} or {dst-order}
134set to "n" are most often used in
135conjunction with Internet addresses and ports as returned by
65.Xr gethostbyname 3 136.Xr gethostbyname 3
66and 137and
67.Xr getservent 3 . 138.Xr getservent 3 .
@@ -75,9 +146,10 @@ functions appeared in
75.Bx 4.2 . 146.Bx 4.2 .
76.Sh BUGS 147.Sh BUGS
77On the 148On the
78.Tn VAX , 149.Tn vax ,
79.Tn ALPHA , 150.Tn alpha ,
80and 151.Tn i386 ,
81.Tn iX86 152and so far
153.Tn mips
82bytes are handled backwards from most everyone else in 154bytes are handled backwards from most everyone else in
83the world. This is not expected to be fixed in the near future. 155the world. This is not expected to be fixed in the near future.