diff options
| author | cvs2svn <admin@example.com> | 1998-10-19 21:47:12 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 1998-10-19 21:47:12 +0000 |
| commit | 5170039cf1df2194faa85741f0733977525cd5c0 (patch) | |
| tree | c667406046ddb1efca5ed4316b02e43494241660 /src/lib/libc/net/byteorder.3 | |
| parent | 536c76cbb863bab152f19842ab88772c01e922c7 (diff) | |
| download | openbsd-OPENBSD_2_4_BASE.tar.gz openbsd-OPENBSD_2_4_BASE.tar.bz2 openbsd-OPENBSD_2_4_BASE.zip | |
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_4_BASE'.OPENBSD_2_4_BASE
Diffstat (limited to 'src/lib/libc/net/byteorder.3')
| -rw-r--r-- | src/lib/libc/net/byteorder.3 | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3 new file mode 100644 index 0000000000..f2788b25dc --- /dev/null +++ b/src/lib/libc/net/byteorder.3 | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | .\" $OpenBSD: byteorder.3,v 1.5 1997/11/19 23:30:17 niklas 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. All advertising materials mentioning features or use of this software | ||
| 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 | ||
| 20 | .\" without specific prior written permission. | ||
| 21 | .\" | ||
| 22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 32 | .\" SUCH DAMAGE. | ||
| 33 | .\" | ||
| 34 | .Dd June 4, 1993 | ||
| 35 | .Dt BYTEORDER 3 | ||
| 36 | .Os BSD 4.2 | ||
| 37 | .Sh NAME | ||
| 38 | .Nm htonl , | ||
| 39 | .Nm htons , | ||
| 40 | .Nm ntohl , | ||
| 41 | .Nm ntohs , | ||
| 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 | ||
| 53 | .Sh SYNOPSIS | ||
| 54 | .Fd #include <sys/types.h> | ||
| 55 | .Fd #include <machine/endian.h> | ||
| 56 | .Ft u_int32_t | ||
| 57 | .Fn htonl "u_int32_t host32" | ||
| 58 | .Ft u_int16_t | ||
| 59 | .Fn htons "u_int16_t host16" | ||
| 60 | .Ft u_int32_t | ||
| 61 | .Fn ntohl "u_int32_t net32" | ||
| 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" | ||
| 84 | .Sh DESCRIPTION | ||
| 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 | ||
| 121 | byte order and host byte order. The last letter (s/l) is a mnemonic | ||
| 122 | for the traditional names for such quantities, short and long, | ||
| 123 | respectively. Today, the C concept of "short"/"long" integers | ||
| 124 | need not coincide with this traditional misunderstanding. | ||
| 125 | On machines which have a byte order which is the same as the network | ||
| 126 | order, routines are defined as null macros. | ||
| 127 | .Pp | ||
| 128 | The functions involving either "be", "le" or "swap" use the numbers | ||
| 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 | ||
| 136 | .Xr gethostbyname 3 | ||
| 137 | and | ||
| 138 | .Xr getservent 3 . | ||
| 139 | .Sh SEE ALSO | ||
| 140 | .Xr gethostbyname 3 , | ||
| 141 | .Xr getservent 3 | ||
| 142 | .Sh HISTORY | ||
| 143 | The | ||
| 144 | .Nm byteorder | ||
| 145 | functions appeared in | ||
| 146 | .Bx 4.2 . | ||
| 147 | .Sh BUGS | ||
| 148 | On the | ||
| 149 | .Tn vax , | ||
| 150 | .Tn alpha , | ||
| 151 | .Tn i386 , | ||
| 152 | and so far | ||
| 153 | .Tn mips | ||
| 154 | bytes are handled backwards from most everyone else in | ||
| 155 | the world. This is not expected to be fixed in the near future. | ||
