| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH BYTEORDER 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
htonl, htons, ntohl, ntohs \- convert values between host and network |
| 10 |
byte order |
| 11 |
.SH LIBRARY |
| 12 |
Standard C library |
| 13 |
.RI ( libc ,\~ \-lc ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B #include <arpa/inet.h> |
| 17 |
.P |
| 18 |
.BI "uint32_t htonl(uint32_t " hostlong ); |
| 19 |
.BI "uint16_t htons(uint16_t " hostshort ); |
| 20 |
.P |
| 21 |
.BI "uint32_t ntohl(uint32_t " netlong ); |
| 22 |
.BI "uint16_t ntohs(uint16_t " netshort ); |
| 23 |
.fi |
| 24 |
.SH DESCRIPTION |
| 25 |
The |
| 26 |
.BR htonl () |
| 27 |
function converts the unsigned integer |
| 28 |
.I hostlong |
| 29 |
from host byte order to network byte order. |
| 30 |
.P |
| 31 |
The |
| 32 |
.BR htons () |
| 33 |
function converts the unsigned short integer |
| 34 |
.I hostshort |
| 35 |
from host byte order to network byte order. |
| 36 |
.P |
| 37 |
The |
| 38 |
.BR ntohl () |
| 39 |
function converts the unsigned integer |
| 40 |
.I netlong |
| 41 |
from network byte order to host byte order. |
| 42 |
.P |
| 43 |
The |
| 44 |
.BR ntohs () |
| 45 |
function converts the unsigned short integer |
| 46 |
.I netshort |
| 47 |
from network byte order to host byte order. |
| 48 |
.P |
| 49 |
On the i386 the host byte order is Least Significant Byte first, |
| 50 |
whereas the network byte order, as used on the Internet, is Most |
| 51 |
Significant Byte first. |
| 52 |
.SH ATTRIBUTES |
| 53 |
For an explanation of the terms used in this section, see |
| 54 |
.BR attributes (7). |
| 55 |
.TS |
| 56 |
allbox; |
| 57 |
lbx lb lb |
| 58 |
l l l. |
| 59 |
Interface Attribute Value |
| 60 |
T{ |
| 61 |
.na |
| 62 |
.nh |
| 63 |
.BR htonl (), |
| 64 |
.BR htons (), |
| 65 |
.BR ntohl (), |
| 66 |
.BR ntohs () |
| 67 |
T} Thread safety MT-Safe |
| 68 |
.TE |
| 69 |
.SH STANDARDS |
| 70 |
POSIX.1-2008. |
| 71 |
.SH HISTORY |
| 72 |
POSIX.1-2001. |
| 73 |
.SH SEE ALSO |
| 74 |
.BR bswap (3), |
| 75 |
.BR endian (3), |
| 76 |
.BR gethostbyname (3), |
| 77 |
.BR getservent (3) |