xref: /illumos-gate/usr/src/man/man3c/byteorder.3c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1.\"
2.\" The contents of this file are subject to the terms of the
3.\" Common Development and Distribution License (the "License").
4.\" You may not use this file except in compliance with the License.
5.\"
6.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7.\" or http://www.opensolaris.org/os/licensing.
8.\" See the License for the specific language governing permissions
9.\" and limitations under the License.
10.\"
11.\" When distributing Covered Code, include this CDDL HEADER in each
12.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13.\" If applicable, add the following below this CDDL HEADER, with the
14.\" fields enclosed by brackets "[]" replaced with your own identifying
15.\" information: Portions Copyright [yyyy] [name of copyright owner]
16.\"
17.\"
18.\" Copyright 1989 AT&T
19.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
20.\" Copyright 2018 Nexenta Systems, Inc.
21.\"
22.Dd August 2, 2018
23.Dt BYTEORDER 3C
24.Os
25.Sh NAME
26.Nm byteorder ,
27.Nm htonl ,
28.Nm htonll ,
29.Nm htons ,
30.Nm ntohl ,
31.Nm ntohll ,
32.Nm ntohs
33.Nd convert values between host and network byte order
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In sys/types.h
38.In netinet/in.h
39.In inttypes.h
40.Ft uint32_t
41.Fo htonl
42.Fa "uint32_t hostlong"
43.Fc
44.Ft uint64_t
45.Fo htonll
46.Fa "uint64_t hostlonglong"
47.Fc
48.Ft uint16_t
49.Fo htons
50.Fa "uint16_t hostshort"
51.Fc
52.Ft uint32_t
53.Fo ntohl
54.Fa "uint32_t netlong"
55.Fc
56.Ft uint64_t
57.Fo ntohll
58.Fa "uint64_t netlonglong"
59.Fc
60.Ft uint16_t
61.Fo ntohs
62.Fa "uint16_t netshort"
63.Fc
64.Sh DESCRIPTION
65These functions convert 16-bit, 32-bit, and 64-bit quantities between network
66byte order and host byte order.
67On some architectures these routines are defined as
68.Dv NULL
69macros in the include file
70.In netinet/in.h .
71On other architectures, the routines are functional when the host byte order is
72different from network byte order.
73.Pp
74These functions are most often used in conjunction with Internet addresses and
75ports as returned by
76.Xr gethostent 3NSL
77and
78.Xr getservent 3SOCKET .
79.Sh MT-LEVEL
80.Sy Safe
81.Sh SEE ALSO
82.Xr inet.h 3HEAD ,
83.Xr gethostent 3NSL ,
84.Xr getservent 3SOCKET ,
85.Xr attributes 7 ,
86.Xr byteorder 7
87