xref: /dflybsd-src/share/man/man9/byteorder.9 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\" Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
286d7f5d3SJohn Marino.\" All rights reserved.
386d7f5d3SJohn Marino.\"
486d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
586d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
686d7f5d3SJohn Marino.\" are met:
786d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
886d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
986d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright
1086d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer in the
1186d7f5d3SJohn Marino.\"    documentation and/or other materials provided with the distribution.
1286d7f5d3SJohn Marino.\"
1386d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1486d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1586d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1686d7f5d3SJohn Marino.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1786d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1886d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1986d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2086d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2186d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2286d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2386d7f5d3SJohn Marino.\" SUCH DAMAGE.
2486d7f5d3SJohn Marino.\"
2586d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man9/byteorder.9,v 1.6 2003/05/21 17:32:55 ru Exp $
2686d7f5d3SJohn Marino.\"
2786d7f5d3SJohn Marino.Dd April 29, 2002
2886d7f5d3SJohn Marino.Dt BYTEORDER 9
2986d7f5d3SJohn Marino.Os
3086d7f5d3SJohn Marino.Sh NAME
3186d7f5d3SJohn Marino.Nm bswap16 , bswap32 , bswap64 ,
3286d7f5d3SJohn Marino.Nm be16toh , be32toh , be64toh , htobe16 , htobe32 , htobe64 ,
3386d7f5d3SJohn Marino.Nm htole16 , htole32 , htole64 , le16toh , le32toh , le64toh ,
3486d7f5d3SJohn Marino.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec ,
3586d7f5d3SJohn Marino.Nm le16enc , le16dec , le32enc , le32dec , le64enc , le64dec
3686d7f5d3SJohn Marino.Nd byte order operations
3786d7f5d3SJohn Marino.Sh SYNOPSIS
3886d7f5d3SJohn Marino.In sys/endian.h
3986d7f5d3SJohn Marino.Ft uint16_t
4086d7f5d3SJohn Marino.Fn bswap16 "uint16_t int16"
4186d7f5d3SJohn Marino.Ft uint32_t
4286d7f5d3SJohn Marino.Fn bswap32 "uint32_t int32"
4386d7f5d3SJohn Marino.Ft uint64_t
4486d7f5d3SJohn Marino.Fn bswap64 "uint64_t int64"
4586d7f5d3SJohn Marino.Ft uint16_t
4686d7f5d3SJohn Marino.Fn be16toh "uint16_t big16"
4786d7f5d3SJohn Marino.Ft uint32_t
4886d7f5d3SJohn Marino.Fn be32toh "uint32_t big32"
4986d7f5d3SJohn Marino.Ft uint64_t
5086d7f5d3SJohn Marino.Fn be64toh "uint64_t big64"
5186d7f5d3SJohn Marino.Ft uint16_t
5286d7f5d3SJohn Marino.Fn htobe16 "uint16_t host16"
5386d7f5d3SJohn Marino.Ft uint32_t
5486d7f5d3SJohn Marino.Fn htobe32 "uint32_t host32"
5586d7f5d3SJohn Marino.Ft uint64_t
5686d7f5d3SJohn Marino.Fn htobe64 "uint64_t host64"
5786d7f5d3SJohn Marino.Ft uint16_t
5886d7f5d3SJohn Marino.Fn htole16 "uint16_t host16"
5986d7f5d3SJohn Marino.Ft uint32_t
6086d7f5d3SJohn Marino.Fn htole32 "uint32_t host32"
6186d7f5d3SJohn Marino.Ft uint64_t
6286d7f5d3SJohn Marino.Fn htole64 "uint64_t host64"
6386d7f5d3SJohn Marino.Ft uint16_t
6486d7f5d3SJohn Marino.Fn le16toh "uint16_t little16"
6586d7f5d3SJohn Marino.Ft uint32_t
6686d7f5d3SJohn Marino.Fn le32toh "uint32_t little32"
6786d7f5d3SJohn Marino.Ft uint64_t
6886d7f5d3SJohn Marino.Fn le64toh "uint64_t little64"
6986d7f5d3SJohn Marino.Ft uint16_t
7086d7f5d3SJohn Marino.Fn be16dec "const void *"
7186d7f5d3SJohn Marino.Ft uint32_t
7286d7f5d3SJohn Marino.Fn be32dec "const void *"
7386d7f5d3SJohn Marino.Ft uint64_t
7486d7f5d3SJohn Marino.Fn be64dec "const void *"
7586d7f5d3SJohn Marino.Ft uint16_t
7686d7f5d3SJohn Marino.Fn le16dec "const void *"
7786d7f5d3SJohn Marino.Ft uint32_t
7886d7f5d3SJohn Marino.Fn le32dec "const void *"
7986d7f5d3SJohn Marino.Ft uint64_t
8086d7f5d3SJohn Marino.Fn le64dec "const void *"
8186d7f5d3SJohn Marino.Ft void
8286d7f5d3SJohn Marino.Fn be16enc "void *" uint16_t
8386d7f5d3SJohn Marino.Ft void
8486d7f5d3SJohn Marino.Fn be32enc "void *" uint32_t
8586d7f5d3SJohn Marino.Ft void
8686d7f5d3SJohn Marino.Fn be64enc "void *" uint64_t
8786d7f5d3SJohn Marino.Ft void
8886d7f5d3SJohn Marino.Fn le16enc "void *" uint16_t
8986d7f5d3SJohn Marino.Ft void
9086d7f5d3SJohn Marino.Fn le32enc "void *" uint32_t
9186d7f5d3SJohn Marino.Ft void
9286d7f5d3SJohn Marino.Fn le64enc "void *" uint64_t
9386d7f5d3SJohn Marino.Sh DESCRIPTION
9486d7f5d3SJohn MarinoThe
9586d7f5d3SJohn Marino.Fn bswap16 ,
9686d7f5d3SJohn Marino.Fn bswap32 ,
9786d7f5d3SJohn Marinoand
9886d7f5d3SJohn Marino.Fn bswap64
9986d7f5d3SJohn Marinofunctions return a byte order swapped integer.
10086d7f5d3SJohn MarinoOn big endian systems, the number is converted to little endian byte order.
10186d7f5d3SJohn MarinoOn little endian systems, the number is converted to big endian byte order.
10286d7f5d3SJohn Marino.Pp
10386d7f5d3SJohn MarinoThe
10486d7f5d3SJohn Marino.Fn be16toh ,
10586d7f5d3SJohn Marino.Fn be32toh ,
10686d7f5d3SJohn Marinoand
10786d7f5d3SJohn Marino.Fn be64toh
10886d7f5d3SJohn Marinofunctions return a big endian byte ordered integer
10986d7f5d3SJohn Marinoconverted to the system's native byte order.
11086d7f5d3SJohn MarinoThe return value will be the same as the argument on big endian systems.
11186d7f5d3SJohn Marino.Pp
11286d7f5d3SJohn MarinoThe
11386d7f5d3SJohn Marino.Fn le16toh ,
11486d7f5d3SJohn Marino.Fn le32toh ,
11586d7f5d3SJohn Marinoand
11686d7f5d3SJohn Marino.Fn le64toh
11786d7f5d3SJohn Marinofunctions return a little endian byte ordered integer
11886d7f5d3SJohn Marinoconverted to the system's native byte order.
11986d7f5d3SJohn MarinoThe return value will be the same as the argument on little endian systems.
12086d7f5d3SJohn Marino.Pp
12186d7f5d3SJohn MarinoThe
12286d7f5d3SJohn Marino.Fn htobe16 ,
12386d7f5d3SJohn Marino.Fn htobe32 ,
12486d7f5d3SJohn Marinoand
12586d7f5d3SJohn Marino.Fn htobe64
12686d7f5d3SJohn Marinofunctions return an integer in the system's native
12786d7f5d3SJohn Marinobyte order converted to big endian byte order.
12886d7f5d3SJohn MarinoThe return value will be the same as the argument on big endian systems.
12986d7f5d3SJohn Marino.Pp
13086d7f5d3SJohn MarinoThe
13186d7f5d3SJohn Marino.Fn htole16 ,
13286d7f5d3SJohn Marino.Fn htole32 ,
13386d7f5d3SJohn Marinoand
13486d7f5d3SJohn Marino.Fn htole64
13586d7f5d3SJohn Marinofunctions return an integer in the system's native
13686d7f5d3SJohn Marinobyte order converted to little endian byte order.
13786d7f5d3SJohn MarinoThe return value will be the same as the argument on little endian systems.
13886d7f5d3SJohn Marino.Pp
13986d7f5d3SJohn MarinoThe
14086d7f5d3SJohn Marino.Fn be16enc ,
14186d7f5d3SJohn Marino.Fn be16dec ,
14286d7f5d3SJohn Marino.Fn be32enc ,
14386d7f5d3SJohn Marino.Fn be32dec ,
14486d7f5d3SJohn Marino.Fn be64enc ,
14586d7f5d3SJohn Marino.Fn be64dec ,
14686d7f5d3SJohn Marino.Fn le16enc ,
14786d7f5d3SJohn Marino.Fn le16dec ,
14886d7f5d3SJohn Marino.Fn le32enc ,
14986d7f5d3SJohn Marino.Fn le32dec ,
15086d7f5d3SJohn Marino.Fn le64enc ,
15186d7f5d3SJohn Marinoand
15286d7f5d3SJohn Marino.Fn le64dec
15386d7f5d3SJohn Marinofunctions encode and decode integers to/from byte strings on any alignment
15486d7f5d3SJohn Marinoin big/little endian format.
15586d7f5d3SJohn Marino.Sh SEE ALSO
15686d7f5d3SJohn Marino.Xr byteorder 3
15786d7f5d3SJohn Marino.Sh HISTORY
15886d7f5d3SJohn MarinoThe
15986d7f5d3SJohn Marino.Fn hto*
16086d7f5d3SJohn Marinoand
16186d7f5d3SJohn Marino.Fn toh*
16286d7f5d3SJohn Marinofunctions first appeared in
16386d7f5d3SJohn Marino.Fx 5.0 ,
16486d7f5d3SJohn Marinoand were originally developed by the
16586d7f5d3SJohn Marino.Nx
16686d7f5d3SJohn Marinoproject.
16786d7f5d3SJohn Marino.Pp
16886d7f5d3SJohn MarinoThe encode/decode functions first appeared in
16986d7f5d3SJohn Marino.Fx 5.1 .
170