diff options
Diffstat (limited to 'src/lib/libc/net/byteorder.3')
| -rw-r--r-- | src/lib/libc/net/byteorder.3 | 186 |
1 files changed, 157 insertions, 29 deletions
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3 index 701a69f688..6625ea1442 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.16 2009/03/17 21:33:04 jmc 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. |
| @@ -11,11 +11,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | 15 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 21 | .\" | 17 | .\" |
| @@ -31,48 +27,180 @@ | |||
| 31 | .\" 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 |
| 32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 33 | .\" | 29 | .\" |
| 34 | .\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 | 30 | .Dd $Mdocdate: March 17 2009 $ |
| 35 | .\" | ||
| 36 | .Dd June 4, 1993 | ||
| 37 | .Dt BYTEORDER 3 | 31 | .Dt BYTEORDER 3 |
| 38 | .Os BSD 4.2 | 32 | .Os |
| 39 | .Sh NAME | 33 | .Sh NAME |
| 40 | .Nm htonl , | 34 | .Nm htonl , |
| 41 | .Nm htons , | 35 | .Nm htons , |
| 42 | .Nm ntohl , | 36 | .Nm ntohl , |
| 43 | .Nm ntohs | 37 | .Nm ntohs , |
| 44 | .Nd convert values between host and network byte order | 38 | .Nm htobe64 , |
| 39 | .Nm htobe32 , | ||
| 40 | .Nm htobe16 , | ||
| 41 | .Nm betoh64 , | ||
| 42 | .Nm betoh32 , | ||
| 43 | .Nm betoh16 , | ||
| 44 | .Nm htole64 , | ||
| 45 | .Nm htole32 , | ||
| 46 | .Nm htole16 , | ||
| 47 | .Nm letoh64 , | ||
| 48 | .Nm letoh32 , | ||
| 49 | .Nm letoh16 , | ||
| 50 | .Nm swap64 , | ||
| 51 | .Nm swap32 , | ||
| 52 | .Nm swap16 | ||
| 53 | .Nd convert values between different byte orderings | ||
| 45 | .Sh SYNOPSIS | 54 | .Sh SYNOPSIS |
| 46 | .Fd #include <sys/param.h> | 55 | .Fd #include <sys/types.h> |
| 47 | .Ft u_long | 56 | .Ft u_int32_t |
| 48 | .Fn htonl "u_long hostlong" | 57 | .Fn htonl "u_int32_t host32" |
| 49 | .Ft u_short | 58 | .Ft u_int16_t |
| 50 | .Fn htons "u_short hostshort" | 59 | .Fn htons "u_int16_t host16" |
| 51 | .Ft u_long | 60 | .Ft u_int32_t |
| 52 | .Fn ntohl "u_long netlong" | 61 | .Fn ntohl "u_int32_t net32" |
| 53 | .Ft u_short | 62 | .Ft u_int16_t |
| 54 | .Fn ntohs "u_short netshort" | 63 | .Fn ntohs "u_int16_t net16" |
| 64 | .Ft u_int64_t | ||
| 65 | .Fn htobe64 "u_int64_t host64" | ||
| 66 | .Ft u_int32_t | ||
| 67 | .Fn htobe32 "u_int32_t host32" | ||
| 68 | .Ft u_int16_t | ||
| 69 | .Fn htobe16 "u_int16_t host16" | ||
| 70 | .Ft u_int64_t | ||
| 71 | .Fn betoh64 "u_int64_t big64" | ||
| 72 | .Ft u_int32_t | ||
| 73 | .Fn betoh32 "u_int32_t big32" | ||
| 74 | .Ft u_int16_t | ||
| 75 | .Fn betoh16 "u_int16_t big16" | ||
| 76 | .Ft u_int64_t | ||
| 77 | .Fn htole64 "u_int64_t host64" | ||
| 78 | .Ft u_int32_t | ||
| 79 | .Fn htole32 "u_int32_t host32" | ||
| 80 | .Ft u_int16_t | ||
| 81 | .Fn htole16 "u_int16_t host16" | ||
| 82 | .Ft u_int64_t | ||
| 83 | .Fn letoh64 "u_int64_t little64" | ||
| 84 | .Ft u_int32_t | ||
| 85 | .Fn letoh32 "u_int32_t little32" | ||
| 86 | .Ft u_int16_t | ||
| 87 | .Fn letoh16 "u_int16_t little16" | ||
| 88 | .Ft u_int64_t | ||
| 89 | .Fn swap64 "u_int64_t val64" | ||
| 90 | .Ft u_int32_t | ||
| 91 | .Fn swap32 "u_int32_t val32" | ||
| 92 | .Ft u_int16_t | ||
| 93 | .Fn swap16 "u_int16_t val16" | ||
| 55 | .Sh DESCRIPTION | 94 | .Sh DESCRIPTION |
| 56 | These routines convert 16 and 32 bit quantities between network | 95 | These routines convert 16, 32 and 64-bit quantities between different |
| 96 | byte orderings. | ||
| 97 | The | ||
| 98 | .Dq swap | ||
| 99 | functions reverse the byte ordering of | ||
| 100 | the given quantity; the others convert either from/to the native | ||
| 101 | byte order used by the host to/from either little- or big-endian (a.k.a | ||
| 102 | network) order. | ||
| 103 | .Pp | ||
| 104 | Apart from the swap functions, the names can be described by this form: | ||
| 105 | {src-order}to{dst-order}{size}. | ||
| 106 | Both {src-order} and {dst-order} can take the following forms: | ||
| 107 | .Pp | ||
| 108 | .Bl -tag -width "be " -offset indent -compact | ||
| 109 | .It h | ||
| 110 | Host order. | ||
| 111 | .It n | ||
| 112 | Network order (big-endian). | ||
| 113 | .It be | ||
| 114 | Big-endian (most significant byte first). | ||
| 115 | .It le | ||
| 116 | Little-endian (least significant byte first). | ||
| 117 | .El | ||
| 118 | .Pp | ||
| 119 | One 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 | ||
| 125 | Long (32-bit, used in conjunction with forms involving | ||
| 126 | .Sq n ) . | ||
| 127 | .It s | ||
| 128 | Short (16-bit, used in conjunction with forms involving | ||
| 129 | .Sq n ) . | ||
| 130 | .It 16 | ||
| 131 | 16-bit. | ||
| 132 | .It 32 | ||
| 133 | 32-bit. | ||
| 134 | .It 64 | ||
| 135 | 64-bit. | ||
| 136 | .El | ||
| 137 | .Pp | ||
| 138 | The swap functions are of the form: swap{size}. | ||
| 139 | .Pp | ||
| 140 | Names involving | ||
| 141 | .Sq n | ||
| 142 | convert quantities between network | ||
| 57 | byte order and host byte order. | 143 | byte order and host byte order. |
| 144 | The last letter | ||
| 145 | .Pf ( Sq s | ||
| 146 | or | ||
| 147 | .Sq l ) | ||
| 148 | is a mnemonic | ||
| 149 | for the traditional names for such quantities, | ||
| 150 | .Li short | ||
| 151 | and | ||
| 152 | .Li long , | ||
| 153 | respectively. | ||
| 154 | Today, the C concept of | ||
| 155 | .Li short | ||
| 156 | and | ||
| 157 | .Li long | ||
| 158 | integers need not coincide with this traditional misunderstanding. | ||
| 58 | On machines which have a byte order which is the same as the network | 159 | On machines which have a byte order which is the same as the network |
| 59 | order, routines are defined as null macros. | 160 | order, routines are defined as null macros. |
| 60 | .Pp | 161 | .Pp |
| 61 | These routines are most often used in conjunction with Internet | 162 | The functions involving either |
| 62 | addresses and ports as returned by | 163 | .Dq be , |
| 164 | .Dq le , | ||
| 165 | or | ||
| 166 | .Dq swap | ||
| 167 | use the numbers | ||
| 168 | 16, 32, or 64 for specifying the bitwidth of the quantities they operate on. | ||
| 169 | Currently all supported architectures are either big- or little-endian | ||
| 170 | so either the | ||
| 171 | .Dq be | ||
| 172 | or | ||
| 173 | .Dq le | ||
| 174 | variants are implemented as null macros. | ||
| 175 | .Pp | ||
| 176 | The routines mentioned above which have either {src-order} or {dst-order} | ||
| 177 | set to | ||
| 178 | .Sq n | ||
| 179 | are most often used in | ||
| 180 | conjunction with Internet addresses and ports as returned by | ||
| 63 | .Xr gethostbyname 3 | 181 | .Xr gethostbyname 3 |
| 64 | and | 182 | and |
| 65 | .Xr getservent 3 . | 183 | .Xr getservent 3 . |
| 66 | .Sh SEE ALSO | 184 | .Sh SEE ALSO |
| 67 | .Xr gethostbyname 3 , | 185 | .Xr gethostbyname 3 , |
| 68 | .Xr getservent 3 | 186 | .Xr getservent 3 |
| 187 | .Sh STANDARDS | ||
| 188 | The | ||
| 189 | .Fn htonl , | ||
| 190 | .Fn htons , | ||
| 191 | .Fn ntohl , | ||
| 192 | and | ||
| 193 | .Fn ntohs | ||
| 194 | functions conform to | ||
| 195 | .St -p1003.1 . | ||
| 196 | The other functions are extensions that should not be used when portability | ||
| 197 | is required. | ||
| 69 | .Sh HISTORY | 198 | .Sh HISTORY |
| 70 | The | 199 | The |
| 71 | .Nm byteorder | 200 | .Nm byteorder |
| 72 | functions appeared in | 201 | functions appeared in |
| 73 | .Bx 4.2 . | 202 | .Bx 4.2 . |
| 74 | .Sh BUGS | 203 | .Sh BUGS |
| 75 | On the | 204 | On the vax, alpha, i386, and some mips architectures, |
| 76 | .Tn VAX | 205 | bytes are handled backwards from most everyone else in the world. |
| 77 | bytes are handled backwards from most everyone else in | 206 | This is not expected to be fixed in the near future. |
| 78 | the world. This is not expected to be fixed in the near future. | ||
