1*86d7f5d3SJohn Marino.\" Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org> 2*86d7f5d3SJohn Marino.\" All rights reserved. 3*86d7f5d3SJohn Marino.\" 4*86d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without 5*86d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions 6*86d7f5d3SJohn Marino.\" are met: 7*86d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 8*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer. 9*86d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 10*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 11*86d7f5d3SJohn Marino.\" documentation and/or other materials provided with the distribution. 12*86d7f5d3SJohn Marino.\" 13*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*86d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*86d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*86d7f5d3SJohn Marino.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*86d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*86d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*86d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*86d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*86d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*86d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*86d7f5d3SJohn Marino.\" SUCH DAMAGE. 24*86d7f5d3SJohn Marino.\" 25*86d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man9/byteorder.9,v 1.6 2003/05/21 17:32:55 ru Exp $ 26*86d7f5d3SJohn Marino.\" 27*86d7f5d3SJohn Marino.Dd April 29, 2002 28*86d7f5d3SJohn Marino.Dt BYTEORDER 9 29*86d7f5d3SJohn Marino.Os 30*86d7f5d3SJohn Marino.Sh NAME 31*86d7f5d3SJohn Marino.Nm bswap16 , bswap32 , bswap64 , 32*86d7f5d3SJohn Marino.Nm be16toh , be32toh , be64toh , htobe16 , htobe32 , htobe64 , 33*86d7f5d3SJohn Marino.Nm htole16 , htole32 , htole64 , le16toh , le32toh , le64toh , 34*86d7f5d3SJohn Marino.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec , 35*86d7f5d3SJohn Marino.Nm le16enc , le16dec , le32enc , le32dec , le64enc , le64dec 36*86d7f5d3SJohn Marino.Nd byte order operations 37*86d7f5d3SJohn Marino.Sh SYNOPSIS 38*86d7f5d3SJohn Marino.In sys/endian.h 39*86d7f5d3SJohn Marino.Ft uint16_t 40*86d7f5d3SJohn Marino.Fn bswap16 "uint16_t int16" 41*86d7f5d3SJohn Marino.Ft uint32_t 42*86d7f5d3SJohn Marino.Fn bswap32 "uint32_t int32" 43*86d7f5d3SJohn Marino.Ft uint64_t 44*86d7f5d3SJohn Marino.Fn bswap64 "uint64_t int64" 45*86d7f5d3SJohn Marino.Ft uint16_t 46*86d7f5d3SJohn Marino.Fn be16toh "uint16_t big16" 47*86d7f5d3SJohn Marino.Ft uint32_t 48*86d7f5d3SJohn Marino.Fn be32toh "uint32_t big32" 49*86d7f5d3SJohn Marino.Ft uint64_t 50*86d7f5d3SJohn Marino.Fn be64toh "uint64_t big64" 51*86d7f5d3SJohn Marino.Ft uint16_t 52*86d7f5d3SJohn Marino.Fn htobe16 "uint16_t host16" 53*86d7f5d3SJohn Marino.Ft uint32_t 54*86d7f5d3SJohn Marino.Fn htobe32 "uint32_t host32" 55*86d7f5d3SJohn Marino.Ft uint64_t 56*86d7f5d3SJohn Marino.Fn htobe64 "uint64_t host64" 57*86d7f5d3SJohn Marino.Ft uint16_t 58*86d7f5d3SJohn Marino.Fn htole16 "uint16_t host16" 59*86d7f5d3SJohn Marino.Ft uint32_t 60*86d7f5d3SJohn Marino.Fn htole32 "uint32_t host32" 61*86d7f5d3SJohn Marino.Ft uint64_t 62*86d7f5d3SJohn Marino.Fn htole64 "uint64_t host64" 63*86d7f5d3SJohn Marino.Ft uint16_t 64*86d7f5d3SJohn Marino.Fn le16toh "uint16_t little16" 65*86d7f5d3SJohn Marino.Ft uint32_t 66*86d7f5d3SJohn Marino.Fn le32toh "uint32_t little32" 67*86d7f5d3SJohn Marino.Ft uint64_t 68*86d7f5d3SJohn Marino.Fn le64toh "uint64_t little64" 69*86d7f5d3SJohn Marino.Ft uint16_t 70*86d7f5d3SJohn Marino.Fn be16dec "const void *" 71*86d7f5d3SJohn Marino.Ft uint32_t 72*86d7f5d3SJohn Marino.Fn be32dec "const void *" 73*86d7f5d3SJohn Marino.Ft uint64_t 74*86d7f5d3SJohn Marino.Fn be64dec "const void *" 75*86d7f5d3SJohn Marino.Ft uint16_t 76*86d7f5d3SJohn Marino.Fn le16dec "const void *" 77*86d7f5d3SJohn Marino.Ft uint32_t 78*86d7f5d3SJohn Marino.Fn le32dec "const void *" 79*86d7f5d3SJohn Marino.Ft uint64_t 80*86d7f5d3SJohn Marino.Fn le64dec "const void *" 81*86d7f5d3SJohn Marino.Ft void 82*86d7f5d3SJohn Marino.Fn be16enc "void *" uint16_t 83*86d7f5d3SJohn Marino.Ft void 84*86d7f5d3SJohn Marino.Fn be32enc "void *" uint32_t 85*86d7f5d3SJohn Marino.Ft void 86*86d7f5d3SJohn Marino.Fn be64enc "void *" uint64_t 87*86d7f5d3SJohn Marino.Ft void 88*86d7f5d3SJohn Marino.Fn le16enc "void *" uint16_t 89*86d7f5d3SJohn Marino.Ft void 90*86d7f5d3SJohn Marino.Fn le32enc "void *" uint32_t 91*86d7f5d3SJohn Marino.Ft void 92*86d7f5d3SJohn Marino.Fn le64enc "void *" uint64_t 93*86d7f5d3SJohn Marino.Sh DESCRIPTION 94*86d7f5d3SJohn MarinoThe 95*86d7f5d3SJohn Marino.Fn bswap16 , 96*86d7f5d3SJohn Marino.Fn bswap32 , 97*86d7f5d3SJohn Marinoand 98*86d7f5d3SJohn Marino.Fn bswap64 99*86d7f5d3SJohn Marinofunctions return a byte order swapped integer. 100*86d7f5d3SJohn MarinoOn big endian systems, the number is converted to little endian byte order. 101*86d7f5d3SJohn MarinoOn little endian systems, the number is converted to big endian byte order. 102*86d7f5d3SJohn Marino.Pp 103*86d7f5d3SJohn MarinoThe 104*86d7f5d3SJohn Marino.Fn be16toh , 105*86d7f5d3SJohn Marino.Fn be32toh , 106*86d7f5d3SJohn Marinoand 107*86d7f5d3SJohn Marino.Fn be64toh 108*86d7f5d3SJohn Marinofunctions return a big endian byte ordered integer 109*86d7f5d3SJohn Marinoconverted to the system's native byte order. 110*86d7f5d3SJohn MarinoThe return value will be the same as the argument on big endian systems. 111*86d7f5d3SJohn Marino.Pp 112*86d7f5d3SJohn MarinoThe 113*86d7f5d3SJohn Marino.Fn le16toh , 114*86d7f5d3SJohn Marino.Fn le32toh , 115*86d7f5d3SJohn Marinoand 116*86d7f5d3SJohn Marino.Fn le64toh 117*86d7f5d3SJohn Marinofunctions return a little endian byte ordered integer 118*86d7f5d3SJohn Marinoconverted to the system's native byte order. 119*86d7f5d3SJohn MarinoThe return value will be the same as the argument on little endian systems. 120*86d7f5d3SJohn Marino.Pp 121*86d7f5d3SJohn MarinoThe 122*86d7f5d3SJohn Marino.Fn htobe16 , 123*86d7f5d3SJohn Marino.Fn htobe32 , 124*86d7f5d3SJohn Marinoand 125*86d7f5d3SJohn Marino.Fn htobe64 126*86d7f5d3SJohn Marinofunctions return an integer in the system's native 127*86d7f5d3SJohn Marinobyte order converted to big endian byte order. 128*86d7f5d3SJohn MarinoThe return value will be the same as the argument on big endian systems. 129*86d7f5d3SJohn Marino.Pp 130*86d7f5d3SJohn MarinoThe 131*86d7f5d3SJohn Marino.Fn htole16 , 132*86d7f5d3SJohn Marino.Fn htole32 , 133*86d7f5d3SJohn Marinoand 134*86d7f5d3SJohn Marino.Fn htole64 135*86d7f5d3SJohn Marinofunctions return an integer in the system's native 136*86d7f5d3SJohn Marinobyte order converted to little endian byte order. 137*86d7f5d3SJohn MarinoThe return value will be the same as the argument on little endian systems. 138*86d7f5d3SJohn Marino.Pp 139*86d7f5d3SJohn MarinoThe 140*86d7f5d3SJohn Marino.Fn be16enc , 141*86d7f5d3SJohn Marino.Fn be16dec , 142*86d7f5d3SJohn Marino.Fn be32enc , 143*86d7f5d3SJohn Marino.Fn be32dec , 144*86d7f5d3SJohn Marino.Fn be64enc , 145*86d7f5d3SJohn Marino.Fn be64dec , 146*86d7f5d3SJohn Marino.Fn le16enc , 147*86d7f5d3SJohn Marino.Fn le16dec , 148*86d7f5d3SJohn Marino.Fn le32enc , 149*86d7f5d3SJohn Marino.Fn le32dec , 150*86d7f5d3SJohn Marino.Fn le64enc , 151*86d7f5d3SJohn Marinoand 152*86d7f5d3SJohn Marino.Fn le64dec 153*86d7f5d3SJohn Marinofunctions encode and decode integers to/from byte strings on any alignment 154*86d7f5d3SJohn Marinoin big/little endian format. 155*86d7f5d3SJohn Marino.Sh SEE ALSO 156*86d7f5d3SJohn Marino.Xr byteorder 3 157*86d7f5d3SJohn Marino.Sh HISTORY 158*86d7f5d3SJohn MarinoThe 159*86d7f5d3SJohn Marino.Fn hto* 160*86d7f5d3SJohn Marinoand 161*86d7f5d3SJohn Marino.Fn toh* 162*86d7f5d3SJohn Marinofunctions first appeared in 163*86d7f5d3SJohn Marino.Fx 5.0 , 164*86d7f5d3SJohn Marinoand were originally developed by the 165*86d7f5d3SJohn Marino.Nx 166*86d7f5d3SJohn Marinoproject. 167*86d7f5d3SJohn Marino.Pp 168*86d7f5d3SJohn MarinoThe encode/decode functions first appeared in 169*86d7f5d3SJohn Marino.Fx 5.1 . 170