1.\" $OpenBSD: htobe64.3,v 1.1 2019/08/30 18:33:17 deraadt 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. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.Dd $Mdocdate: August 30 2019 $ 31.Dt HTOBE64 3 32.Os 33.Sh NAME 34.Nm htobe64 , 35.Nm htobe32 , 36.Nm htobe16 , 37.Nm be64toh , 38.Nm be32toh , 39.Nm be16toh , 40.Nm betoh64 , 41.Nm betoh32 , 42.Nm betoh16 , 43.Nm htole64 , 44.Nm htole32 , 45.Nm htole16 , 46.Nm le64toh , 47.Nm le32toh , 48.Nm le16toh , 49.Nm letoh64 , 50.Nm letoh32 , 51.Nm letoh16 , 52.Nm swap64 , 53.Nm swap32 , 54.Nm swap16 55.Nd convert values between different byte orderings 56.Sh SYNOPSIS 57.In endian.h 58.Ft uint64_t 59.Fn htobe64 "uint64_t host64" 60.Ft uint32_t 61.Fn htobe32 "uint32_t host32" 62.Ft uint16_t 63.Fn htobe16 "uint16_t host16" 64.Ft uint64_t 65.Fn be64toh "uint64_t big64" 66.Ft uint32_t 67.Fn be32toh "uint32_t big32" 68.Ft uint16_t 69.Fn be16toh "uint16_t big16" 70.Ft uint64_t 71.Fn betoh64 "uint64_t big64" 72.Ft uint32_t 73.Fn betoh32 "uint32_t big32" 74.Ft uint16_t 75.Fn betoh16 "uint16_t big16" 76.Ft uint64_t 77.Fn htole64 "uint64_t host64" 78.Ft uint32_t 79.Fn htole32 "uint32_t host32" 80.Ft uint16_t 81.Fn htole16 "uint16_t host16" 82.Ft uint64_t 83.Fn letoh64 "uint64_t little64" 84.Ft uint64_t 85.Fn le64toh "uint64_t little64" 86.Ft uint32_t 87.Fn le32toh "uint32_t little32" 88.Ft uint16_t 89.Fn le16toh "uint16_t little16" 90.Ft uint32_t 91.Fn letoh32 "uint32_t little32" 92.Ft uint16_t 93.Fn letoh16 "uint16_t little16" 94.Ft uint64_t 95.Fn swap64 "uint64_t val64" 96.Ft uint32_t 97.Fn swap32 "uint32_t val32" 98.Ft uint16_t 99.Fn swap16 "uint16_t val16" 100.Sh DESCRIPTION 101These routines convert 16, 32 and 64-bit quantities between different 102byte orderings. 103The 104.Dq swap 105functions reverse the byte ordering of 106the given quantity; the others convert either from/to the native 107byte order used by the host to/from either little- or big-endian (a.k.a 108network) order. 109.Pp 110Apart from the swap functions, 111the names containing 112.Dq be 113convert between host and big-endian (most significant byte first) order 114of the given quantity, while the names containing 115.Dq le 116convert between host and little-endian (least significant byte first) order 117of the given quantity. 118.Pp 119All these functions use the numbers 12016, 32, or 64 for specifying the bitwidth of the quantities they operate on. 121Currently all supported architectures are either big- or little-endian 122so either the 123.Dq be 124or 125.Dq le 126variants are implemented as null macros. 127.Sh SEE ALSO 128.Xr htonl 3 129.Sh STANDARDS 130The 131.Fn htobe64 , 132.Fn htobe32 , 133.Fn htobe16 , 134.Fn be64toh , 135.Fn be32toh , 136.Fn be16toh , 137.Fn htole64 , 138.Fn htole32 , 139.Fn htole16 , 140.Fn le64toh , 141.Fn le32toh , 142and 143.Fn le16toh 144functions are expected to conform to a future version of 145.St -p1003.1 . 146The other functions are extensions that should not be used 147when portability is required. 148.Sh HISTORY 149The 150.Nm swap{size} 151and 152.Nm {src-order}to{dst-order}{size} 153functions appeared in 154.Bx 4.2 . 155The 156.Nm {src-order}{size}to{dst-order} 157functions appeared in 158.Ox 5.6 . 159A subset of them was submitted for standardization after 160.St -p1003.1-2008 . 161.Sh BUGS 162The perceived antagonism between 163.Sq host 164and 165.Sq network 166byte order does not allow PDP-11 users to sleep soundly at night. 167