xref: /freebsd/share/man/man9/byteorder.9 (revision 3f4655de4be8f127ffd34cb7dc4ac6cde9b2cca3)
18a1791edSMike Barcroft.\" Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
28a1791edSMike Barcroft.\" All rights reserved.
38a1791edSMike Barcroft.\"
48a1791edSMike Barcroft.\" Redistribution and use in source and binary forms, with or without
58a1791edSMike Barcroft.\" modification, are permitted provided that the following conditions
68a1791edSMike Barcroft.\" are met:
78a1791edSMike Barcroft.\" 1. Redistributions of source code must retain the above copyright
88a1791edSMike Barcroft.\"    notice, this list of conditions and the following disclaimer.
98a1791edSMike Barcroft.\" 2. Redistributions in binary form must reproduce the above copyright
108a1791edSMike Barcroft.\"    notice, this list of conditions and the following disclaimer in the
118a1791edSMike Barcroft.\"    documentation and/or other materials provided with the distribution.
128a1791edSMike Barcroft.\"
138a1791edSMike Barcroft.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
148a1791edSMike Barcroft.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158a1791edSMike Barcroft.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
168a1791edSMike Barcroft.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
178a1791edSMike Barcroft.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
188a1791edSMike Barcroft.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
198a1791edSMike Barcroft.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
208a1791edSMike Barcroft.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
218a1791edSMike Barcroft.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
228a1791edSMike Barcroft.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
238a1791edSMike Barcroft.\" SUCH DAMAGE.
248a1791edSMike Barcroft.\"
258a1791edSMike Barcroft.\" $FreeBSD$
268a1791edSMike Barcroft.\"
273f4655deSMike Barcroft.Dd April 29, 2002
288a1791edSMike Barcroft.Dt BYTEORDER 9
298a1791edSMike Barcroft.Os
308a1791edSMike Barcroft.Sh NAME
318a1791edSMike Barcroft.Nm be16toh ,
328a1791edSMike Barcroft.Nm be32toh ,
338a1791edSMike Barcroft.Nm be64toh ,
348a1791edSMike Barcroft.Nm htobe16 ,
358a1791edSMike Barcroft.Nm htobe32 ,
368a1791edSMike Barcroft.Nm htobe64 ,
378a1791edSMike Barcroft.Nm htole16 ,
388a1791edSMike Barcroft.Nm htole32 ,
398a1791edSMike Barcroft.Nm htole64 ,
408a1791edSMike Barcroft.Nm le16toh ,
418a1791edSMike Barcroft.Nm le32toh ,
428a1791edSMike Barcroft.Nm le64toh
438a1791edSMike Barcroft.Nd convert values between big endian, little endian, and host byte order
448a1791edSMike Barcroft.Sh SYNOPSIS
453f4655deSMike Barcroft.In sys/endian.h
463f4655deSMike Barcroft.Ft uint16_t
473f4655deSMike Barcroft.Fn bswap16 "uint16_t int16"
483f4655deSMike Barcroft.Ft uint32_t
493f4655deSMike Barcroft.Fn bswap32 "uint32_t int32"
503f4655deSMike Barcroft.Ft uint64_t
513f4655deSMike Barcroft.Fn bswap64 "uint64_t int64"
528a1791edSMike Barcroft.Ft uint16_t
538a1791edSMike Barcroft.Fn be16toh "uint16_t big16"
548a1791edSMike Barcroft.Ft uint32_t
558a1791edSMike Barcroft.Fn be32toh "uint32_t big32"
568a1791edSMike Barcroft.Ft uint64_t
578a1791edSMike Barcroft.Fn be64toh "uint64_t big64"
588a1791edSMike Barcroft.Ft uint16_t
598a1791edSMike Barcroft.Fn htobe16 "uint16_t host16"
608a1791edSMike Barcroft.Ft uint32_t
618a1791edSMike Barcroft.Fn htobe32 "uint32_t host32"
628a1791edSMike Barcroft.Ft uint64_t
638a1791edSMike Barcroft.Fn htobe64 "uint64_t host64"
648a1791edSMike Barcroft.Ft uint16_t
658a1791edSMike Barcroft.Fn htole16 "uint16_t host16"
668a1791edSMike Barcroft.Ft uint32_t
678a1791edSMike Barcroft.Fn htole32 "uint32_t host32"
688a1791edSMike Barcroft.Ft uint64_t
698a1791edSMike Barcroft.Fn htole64 "uint64_t host64"
708a1791edSMike Barcroft.Ft uint16_t
718a1791edSMike Barcroft.Fn le16toh "uint16_t little16"
728a1791edSMike Barcroft.Ft uint32_t
738a1791edSMike Barcroft.Fn le32toh "uint32_t little32"
748a1791edSMike Barcroft.Ft uint64_t
758a1791edSMike Barcroft.Fn le64toh "uint64_t little64"
768a1791edSMike Barcroft.Sh DESCRIPTION
778a1791edSMike BarcroftThe
783f4655deSMike Barcroft.Fn bswap16 ,
793f4655deSMike Barcroft.Fn bswap32 ,
803f4655deSMike Barcroftand
813f4655deSMike Barcroft.Fn bswap64
823f4655deSMike Barcroftfunctions return a byte order swapped integer.
833f4655deSMike BarcroftOn big endian systems, the number is converted to little endian byte order.
843f4655deSMike BarcroftOn little endian systems, the number is converted to big endian byte order.
853f4655deSMike Barcroft.Pp
863f4655deSMike BarcroftThe
878a1791edSMike Barcroft.Fn be16toh ,
888a1791edSMike Barcroft.Fn be32toh ,
898a1791edSMike Barcroftand
908a1791edSMike Barcroft.Fn be64toh
918a1791edSMike Barcroftfunctions return a big endian byte ordered integer
928a1791edSMike Barcroftconverted to the system's native byte order.
938a1791edSMike BarcroftThe return value will be the same as the argument on big endian systems.
948a1791edSMike Barcroft.Pp
958a1791edSMike BarcroftThe
968a1791edSMike Barcroft.Fn le16toh ,
978a1791edSMike Barcroft.Fn le32toh ,
988a1791edSMike Barcroftand
998a1791edSMike Barcroft.Fn le64toh
1008a1791edSMike Barcroftfunctions return a little endian byte ordered integer
1018a1791edSMike Barcroftconverted to the system's native byte order.
1028a1791edSMike BarcroftThe return value will be the same as the argument on little endian systems.
1038a1791edSMike Barcroft.Pp
1048a1791edSMike BarcroftThe
1058a1791edSMike Barcroft.Fn htobe16 ,
1068a1791edSMike Barcroft.Fn htobe32 ,
1078a1791edSMike Barcroftand
1088a1791edSMike Barcroft.Fn htobe64
1098a1791edSMike Barcroftfunctions return a integer in the system's native
1108a1791edSMike Barcroftbyte order converted to big endian byte order.
1118a1791edSMike BarcroftThe return value will be the same as the argument on big endian systems.
1128a1791edSMike Barcroft.Pp
1138a1791edSMike BarcroftThe
1148a1791edSMike Barcroft.Fn htole16 ,
1158a1791edSMike Barcroft.Fn htole32 ,
1168a1791edSMike Barcroftand
1178a1791edSMike Barcroft.Fn htole64
1188a1791edSMike Barcroftfunctions return a integer in the system's native
1198a1791edSMike Barcroftbyte order converted to little endian byte order.
1208a1791edSMike BarcroftThe return value will be the same as the argument on little endian systems.
1218a1791edSMike Barcroft.Sh SEE ALSO
1228a1791edSMike Barcroft.Xr byteorder 3
1238a1791edSMike Barcroft.Sh HISTORY
1248a1791edSMike BarcroftThese functions first appeared in
1258a1791edSMike Barcroft.Fx 5.0 ,
1268a1791edSMike Barcroftand were originally developed by the
1278a1791edSMike Barcroft.Nx
1288a1791edSMike Barcroftproject.
129