diff options
Diffstat (limited to 'src/lib/libc/net/byteorder.3')
| -rw-r--r-- | src/lib/libc/net/byteorder.3 | 151 |
1 files changed, 128 insertions, 23 deletions
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3 index 701a69f688..9d8fa7221f 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.8 2000/04/18 03:01:30 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. |
| @@ -31,35 +31,141 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 | ||
| 35 | .\" | ||
| 36 | .Dd June 4, 1993 | 34 | .Dd June 4, 1993 |
| 37 | .Dt BYTEORDER 3 | 35 | .Dt BYTEORDER 3 |
| 38 | .Os BSD 4.2 | 36 | .Os |
| 39 | .Sh NAME | 37 | .Sh NAME |
| 40 | .Nm htonl , | 38 | .Nm htonl , |
| 41 | .Nm htons , | 39 | .Nm htons , |
| 42 | .Nm ntohl , | 40 | .Nm ntohl , |
| 43 | .Nm ntohs | 41 | .Nm ntohs , |
| 44 | .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 | ||
| 45 | .Sh SYNOPSIS | 53 | .Sh SYNOPSIS |
| 46 | .Fd #include <sys/param.h> | 54 | .Fd #include <sys/types.h> |
| 47 | .Ft u_long | 55 | .Fd #include <machine/endian.h> |
| 48 | .Fn htonl "u_long hostlong" | 56 | .Ft u_int32_t |
| 49 | .Ft u_short | 57 | .Fn htonl "u_int32_t host32" |
| 50 | .Fn htons "u_short hostshort" | 58 | .Ft u_int16_t |
| 51 | .Ft u_long | 59 | .Fn htons "u_int16_t host16" |
| 52 | .Fn ntohl "u_long netlong" | 60 | .Ft u_int32_t |
| 53 | .Ft u_short | 61 | .Fn ntohl "u_int32_t net32" |
| 54 | .Fn ntohs "u_short netshort" | 62 | .Ft u_int16_t |
| 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" | ||
| 55 | .Sh DESCRIPTION | 84 | .Sh DESCRIPTION |
| 56 | These routines convert 16 and 32 bit quantities between network | 85 | These routines convert 16- and 32-bit quantities between different |
| 86 | byte orderings. | ||
| 87 | The | ||
| 88 | .Dq swap | ||
| 89 | functions reverse the byte ordering of | ||
| 90 | the given quantity, the others converts either from/to the native | ||
| 91 | byte order used by the host to/from either little- or big-endian (a.k.a | ||
| 92 | network) order. | ||
| 93 | .Pp | ||
| 94 | Apart from the swap functions, the names can be described by this form: | ||
| 95 | {src-order}to{dst-order}{size}. | ||
| 96 | Both {src-order} and {dst-order} can take the following forms: | ||
| 97 | .Pp | ||
| 98 | .Bl -tag -width "be " -offset indent -compact | ||
| 99 | .It h | ||
| 100 | Host order. | ||
| 101 | .It n | ||
| 102 | Network order (big-endian). | ||
| 103 | .It be | ||
| 104 | Big-endian (most significant byte first). | ||
| 105 | .It le | ||
| 106 | Little-endian (least significant byte first). | ||
| 107 | .El | ||
| 108 | .Pp | ||
| 109 | One of the specified orderings must be | ||
| 110 | .Sq h . | ||
| 111 | {size} will take these forms: | ||
| 112 | .Pp | ||
| 113 | .Bl -tag -width "32 " -offset indent -compact | ||
| 114 | .It l | ||
| 115 | Long (32-bit, used in conjunction with forms involving | ||
| 116 | .Sq n ) . | ||
| 117 | .It s | ||
| 118 | Short (16-bit, used in conjunction with forms involving | ||
| 119 | .Sq n ) . | ||
| 120 | .It 16 | ||
| 121 | 16-bit. | ||
| 122 | .It 32 | ||
| 123 | 32-bit. | ||
| 124 | .El | ||
| 125 | .Pp | ||
| 126 | The swap functions are of the form: swap{size}. | ||
| 127 | .Pp | ||
| 128 | Names involving | ||
| 129 | .Sq n | ||
| 130 | convert quantities between network | ||
| 57 | byte order and host byte order. | 131 | byte order and host byte order. |
| 132 | The last letter | ||
| 133 | .Pf ( Sq s | ||
| 134 | or | ||
| 135 | .Sq l ) | ||
| 136 | is a mnemonic | ||
| 137 | for the traditional names for such quantities, | ||
| 138 | .Li short | ||
| 139 | and | ||
| 140 | .Li long , | ||
| 141 | respectively. | ||
| 142 | Today, the C concept of | ||
| 143 | .Li short | ||
| 144 | and | ||
| 145 | .Li long | ||
| 146 | integers need not coincide with this traditional misunderstanding. | ||
| 58 | On machines which have a byte order which is the same as the network | 147 | On machines which have a byte order which is the same as the network |
| 59 | order, routines are defined as null macros. | 148 | order, routines are defined as null macros. |
| 60 | .Pp | 149 | .Pp |
| 61 | These routines are most often used in conjunction with Internet | 150 | The functions involving either |
| 62 | addresses and ports as returned by | 151 | .Dq be , |
| 152 | .Dq le , | ||
| 153 | or | ||
| 154 | .Dq swap | ||
| 155 | use the numbers | ||
| 156 | 16 and 32 for specifying the bitwidth of the quantities they operate on. | ||
| 157 | Currently all supported architectures are either big- or little-endian | ||
| 158 | so either the | ||
| 159 | .Dq be | ||
| 160 | or | ||
| 161 | .Dq le | ||
| 162 | variants are implemented as null macros. | ||
| 163 | .Pp | ||
| 164 | The routines mentioned above which have either {src-order} or {dst-order} | ||
| 165 | set to | ||
| 166 | .Sq n | ||
| 167 | are most often used in | ||
| 168 | conjunction with Internet addresses and ports as returned by | ||
| 63 | .Xr gethostbyname 3 | 169 | .Xr gethostbyname 3 |
| 64 | and | 170 | and |
| 65 | .Xr getservent 3 . | 171 | .Xr getservent 3 . |
| @@ -69,10 +175,9 @@ and | |||
| 69 | .Sh HISTORY | 175 | .Sh HISTORY |
| 70 | The | 176 | The |
| 71 | .Nm byteorder | 177 | .Nm byteorder |
| 72 | functions appeared in | 178 | functions appeared in |
| 73 | .Bx 4.2 . | 179 | .Bx 4.2 . |
| 74 | .Sh BUGS | 180 | .Sh BUGS |
| 75 | On the | 181 | On the vax, alpha, i386, and so far mips, |
| 76 | .Tn VAX | 182 | bytes are handled backwards from most everyone else in the world. |
| 77 | bytes are handled backwards from most everyone else in | 183 | 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. | ||
