1BYTEORDER(3) Linux Programmer's Manual BYTEORDER(3)
2
3
4
6 htonl, htons, ntohl, ntohs - convert values between host and network
7 byte order
8
10 #include <arpa/inet.h>
11
12 uint32_t htonl(uint32_t hostlong);
13 uint16_t htons(uint16_t hostshort);
14
15 uint32_t ntohl(uint32_t netlong);
16 uint16_t ntohs(uint16_t netshort);
17
19 The htonl() function converts the unsigned integer hostlong from host
20 byte order to network byte order.
21
22 The htons() function converts the unsigned short integer hostshort from
23 host byte order to network byte order.
24
25 The ntohl() function converts the unsigned integer netlong from network
26 byte order to host byte order.
27
28 The ntohs() function converts the unsigned short integer netshort from
29 network byte order to host byte order.
30
31 On the i386 the host byte order is Least Significant Byte first,
32 whereas the network byte order, as used on the Internet, is Most Sig‐
33 nificant Byte first.
34
36 For an explanation of the terms used in this section, see at‐
37 tributes(7).
38
39 ┌────────────────────────────────────────────┬───────────────┬─────────┐
40 │Interface │ Attribute │ Value │
41 ├────────────────────────────────────────────┼───────────────┼─────────┤
42 │htonl(), htons(), ntohl(), ntohs() │ Thread safety │ MT-Safe │
43 └────────────────────────────────────────────┴───────────────┴─────────┘
44
46 POSIX.1-2001, POSIX.1-2008.
47
48 Some systems require the inclusion of <netinet/in.h> instead of
49 <arpa/inet.h>.
50
52 bswap(3), endian(3), gethostbyname(3), getservent(3)
53
55 This page is part of release 5.13 of the Linux man-pages project. A
56 description of the project, information about reporting bugs, and the
57 latest version of this page, can be found at
58 https://www.kernel.org/doc/man-pages/.
59
60
61
62GNU 2021-03-22 BYTEORDER(3)