diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/net/Makefile.inc | 7 | ||||
| -rw-r--r-- | src/lib/libc/net/byteorder.3 | 92 |
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 | ||
| 28 | MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ | 28 | MLINKS+=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 | ||
| 30 | MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ | 33 | MLINKS+=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 |
| 32 | MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ | 35 | MLINKS+=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 |
| 55 | These routines convert 16 and 32 bit quantities between network | 85 | These routines convert 16 and 32 bit quantities between different |
| 86 | byte orderings. The "swap" functions reverse the byte ordering of | ||
| 87 | the given quantity, the others converts either from/to the native | ||
| 88 | byte order used by the host to/from either little- or big-endian (a.k.a | ||
| 89 | network) order. | ||
| 90 | .Pp | ||
| 91 | Apart from the "swap" functions, the names can be described by this form: | ||
| 92 | {src-order}to{dst-order}{size}. | ||
| 93 | Both {src-order} and {dst-order} can take the following forms: | ||
| 94 | .Bl -tag -width "be " | ||
| 95 | .It Em h | ||
| 96 | host order | ||
| 97 | .It Em n | ||
| 98 | network order (big-endian) | ||
| 99 | .It Em be | ||
| 100 | big-endian (Most significant byte first) | ||
| 101 | .It Em le | ||
| 102 | little-endian (Least significant byte first) | ||
| 103 | .El | ||
| 104 | .Pp | ||
| 105 | One of the specified orderings must be "h". | ||
| 106 | {Size} will take these forms: | ||
| 107 | .Bl -tag -width "32 " | ||
| 108 | .It Em l | ||
| 109 | long (32-bit, used in conjunction with forms involving "n") | ||
| 110 | .It Em s | ||
| 111 | short (16-bit, used in conjunction with forms involving "n") | ||
| 112 | .It Em 16 | ||
| 113 | 16-bit | ||
| 114 | .It Em 32 | ||
| 115 | 32-bit | ||
| 116 | .El | ||
| 117 | .Pp | ||
| 118 | The "swap" functions are of the form: swap{size}. | ||
| 119 | .Pp | ||
| 120 | Names involving "n" convert quantities between network | ||
| 56 | byte order and host byte order. The last letter (s/l) is a mnemonic | 121 | byte order and host byte order. The last letter (s/l) is a mnemonic |
| 57 | for the traditional names for such quantities, short and long, | 122 | for the traditional names for such quantities, short and long, |
| 58 | respectively. Today, the C concept of "short"/"long" integers | 123 | respectively. Today, the C concept of "short"/"long" integers |
| @@ -60,8 +125,14 @@ need not coincide with this traditional misunderstanding. | |||
| 60 | On machines which have a byte order which is the same as the network | 125 | On machines which have a byte order which is the same as the network |
| 61 | order, routines are defined as null macros. | 126 | order, routines are defined as null macros. |
| 62 | .Pp | 127 | .Pp |
| 63 | These routines are most often used in conjunction with Internet | 128 | The functions involving either "be", "le" or "swap" use the numbers |
| 64 | addresses and ports as returned by | 129 | (16/32) for specifying the bitwidth of the quantities they operate on. |
| 130 | Currently all supported architectures are either big- or little-endian | ||
| 131 | so either the "be" or the "le" variants are implemented as null macros. | ||
| 132 | .Pp | ||
| 133 | The routines mentioned above which have either {src-order} or {dst-order} | ||
| 134 | set to "n" are most often used in | ||
| 135 | conjunction with Internet addresses and ports as returned by | ||
| 65 | .Xr gethostbyname 3 | 136 | .Xr gethostbyname 3 |
| 66 | and | 137 | and |
| 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 |
| 77 | On the | 148 | On the |
| 78 | .Tn VAX , | 149 | .Tn vax , |
| 79 | .Tn ALPHA , | 150 | .Tn alpha , |
| 80 | and | 151 | .Tn i386 , |
| 81 | .Tn iX86 | 152 | and so far |
| 153 | .Tn mips | ||
| 82 | bytes are handled backwards from most everyone else in | 154 | bytes are handled backwards from most everyone else in |
| 83 | the world. This is not expected to be fixed in the near future. | 155 | the world. This is not expected to be fixed in the near future. |
