]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
3d54a910 MK |
2 | .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
3 | .\" <mtk.manpages@gmail.com> | |
fea681da | 4 | .\" |
4b72fb64 | 5 | .\" %%%LICENSE_START(verbatim) |
fea681da MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
fea681da MK |
26 | .\" |
27 | .\" References consulted: | |
28 | .\" Linux libc source code | |
29 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
30 | .\" 386BSD man pages | |
31 | .\" libc.info (from glibc distribution) | |
32 | .\" Modified Sat Jul 24 19:12:00 1993 by Rik Faith <faith@cs.unc.edu> | |
33 | .\" Modified Sun Sep 3 20:29:36 1995 by Jim Van Zandt <jrv@vanzandt.mv.com> | |
34 | .\" Changed network into host byte order (for inet_network), | |
35 | .\" Andreas Jaeger <aj@arthur.rhein-neckar.de>, 980130. | |
054f5228 MK |
36 | .\" 2008-06-19, mtk |
37 | .\" Describe the various address forms supported by inet_aton(). | |
38 | .\" Clarify discussion of inet_lnaof(), inet_netof(), and inet_makeaddr(). | |
39 | .\" Add discussion of Classful Addressing, noting that it is obsolete. | |
40 | .\" Added an EXAMPLE program. | |
fea681da | 41 | .\" |
7d90b3d3 | 42 | .TH INET 3 2013-02-10 "GNU" "Linux Programmer's Manual" |
fea681da | 43 | .SH NAME |
c13182ef | 44 | inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof, |
fea681da MK |
45 | inet_netof \- Internet address manipulation routines |
46 | .SH SYNOPSIS | |
47 | .nf | |
48 | .B #include <sys/socket.h> | |
49 | .B #include <netinet/in.h> | |
50 | .B #include <arpa/inet.h> | |
51 | .sp | |
52 | .BI "int inet_aton(const char *" cp ", struct in_addr *" inp ); | |
53 | .sp | |
54 | .BI "in_addr_t inet_addr(const char *" cp ); | |
55 | .sp | |
56 | .BI "in_addr_t inet_network(const char *" cp ); | |
57 | .sp | |
58 | .BI "char *inet_ntoa(struct in_addr " in ); | |
59 | .sp | |
60 | .BI "struct in_addr inet_makeaddr(int " net ", int " host ); | |
61 | .sp | |
62 | .BI "in_addr_t inet_lnaof(struct in_addr " in ); | |
63 | .sp | |
64 | .BI "in_addr_t inet_netof(struct in_addr " in ); | |
65 | .fi | |
cc4615cc MK |
66 | .sp |
67 | .in -4n | |
68 | Feature Test Macro Requirements for glibc (see | |
69 | .BR feature_test_macros (7)): | |
70 | .in | |
71 | .sp | |
72 | .BR inet_aton (), | |
73 | .BR inet_ntoa (): | |
74 | _BSD_SOURCE || _SVID_SOURCE | |
fea681da | 75 | .SH DESCRIPTION |
60a90ecd MK |
76 | .BR inet_aton () |
77 | converts the Internet host address \fIcp\fP from the | |
054f5228 MK |
78 | IPv4 numbers-and-dots notation into binary form (in network byte order) |
79 | and stores it in the structure that \fIinp\fP points to. | |
60a90ecd | 80 | .BR inet_aton () |
c7094399 | 81 | returns nonzero if the address is valid, zero if not. |
054f5228 MK |
82 | The address supplied in |
83 | .I cp | |
84 | can have one of the following forms: | |
85 | .TP 10 | |
86 | .I a.b.c.d | |
57e5ca03 | 87 | Each of the four numeric parts specifies a byte of the address; |
054f5228 MK |
88 | the bytes are assigned in left-to-right order to produce the binary address. |
89 | .TP | |
90 | .I a.b.c | |
91 | Parts | |
92 | .I a | |
93 | and | |
94 | .I b | |
95 | specify the first two bytes of the binary address. | |
96 | Part | |
97 | .I c | |
98 | is interpreted as a 16-bit value that defines the rightmost two bytes | |
99 | of the binary address. | |
100 | This notation is suitable for specifying (outmoded) Class B | |
101 | network addresses. | |
102 | .TP | |
103 | .I a.b | |
104 | Part | |
105 | .I a | |
106 | specifies the first byte of the binary address. | |
107 | Part | |
108 | .I b | |
109 | is interpreted as a 24-bit value that defines the rightmost three bytes | |
110 | of the binary address. | |
111 | This notation is suitable for specifying (outmoded) Class C | |
112 | network addresses. | |
113 | .TP | |
114 | .I a | |
115 | The value | |
116 | .I a | |
117 | is interpreted as a 32-bit value that is stored directly | |
118 | into the binary address without any byte rearrangement. | |
119 | .PP | |
120 | In all of the above forms, | |
121 | components of the dotted address can be specified in decimal, | |
122 | octal (with a leading | |
123 | .IR 0 ), | |
124 | or hexadecimal, with a leading | |
125 | .IR 0X ). | |
126 | Addresses in any of these forms are collectively termed | |
127 | .IR "IPV4 numbers-and-dots notation" . | |
128 | The form that uses exactly four decimal numbers is referred to as | |
129 | .IR "IPv4 dotted-decimal notation" | |
130 | (or sometimes: | |
131 | .IR "IPv4 dotted-quad notation" ). | |
fea681da | 132 | .PP |
60a90ecd MK |
133 | The |
134 | .BR inet_addr () | |
135 | function converts the Internet host address | |
054f5228 | 136 | \fIcp\fP from IPv4 numbers-and-dots notation into binary data in network |
c13182ef | 137 | byte order. |
2f0af33b MK |
138 | If the input is invalid, |
139 | .B INADDR_NONE | |
140 | (usually \-1) is returned. | |
054f5228 MK |
141 | Use of this function is problematic because \-1 is a valid address |
142 | (255.255.255.255). | |
143 | Avoid its use in favor of | |
60a90ecd | 144 | .BR inet_aton (), |
054f5228 MK |
145 | .BR inet_pton (3), |
146 | or | |
147 | .BR getaddrinfo (3) | |
148 | which provide a cleaner way to indicate error return. | |
fea681da | 149 | .PP |
60a90ecd MK |
150 | The |
151 | .BR inet_network () | |
054f5228 MK |
152 | function converts |
153 | .IR cp , | |
154 | a string in IPv4 numbers-and-dots notation, | |
155 | into a number in host byte order suitable for use as an | |
156 | Internet network address. | |
157 | On success, the converted address is returned. | |
7cc028fb | 158 | If the input is invalid, \-1 is returned. |
fea681da | 159 | .PP |
60a90ecd MK |
160 | The |
161 | .BR inet_ntoa () | |
162 | function converts the Internet host address | |
054f5228 MK |
163 | \fIin\fP, given in network byte order, to a string in IPv4 |
164 | dotted-decimal notation. | |
c13182ef | 165 | The string is returned in a statically |
fea681da MK |
166 | allocated buffer, which subsequent calls will overwrite. |
167 | .PP | |
60a90ecd | 168 | The |
60a90ecd | 169 | .BR inet_lnaof () |
054f5228 | 170 | function returns the local network address part |
c13182ef | 171 | of the Internet address \fIin\fP. |
054f5228 | 172 | The returned value is in host byte order. |
fea681da | 173 | .PP |
60a90ecd MK |
174 | The |
175 | .BR inet_netof () | |
176 | function returns the network number part of | |
054f5228 MK |
177 | the Internet address \fIin\fP. |
178 | The returned value is in host byte order. | |
179 | .PP | |
180 | The | |
181 | .BR inet_makeaddr () | |
182 | function is the converse of | |
61792fc6 | 183 | .BR inet_netof () |
054f5228 MK |
184 | and |
185 | .BR inet_lnaof (). | |
186 | It returns an Internet host address in network byte order, | |
187 | created by combining the network number \fInet\fP | |
188 | with the local address \fIhost\fP, both in | |
189 | host byte order. | |
fea681da | 190 | .PP |
60a90ecd MK |
191 | The structure \fIin_addr\fP as used in |
192 | .BR inet_ntoa (), | |
193 | .BR inet_makeaddr (), | |
3c775eb7 | 194 | .BR inet_lnaof () |
60a90ecd MK |
195 | and |
196 | .BR inet_netof () | |
a9a13a50 MK |
197 | is defined in |
198 | .I <netinet/in.h> | |
199 | as: | |
fea681da | 200 | .sp |
bd191423 | 201 | .in +4n |
fea681da | 202 | .nf |
9f8162f9 MK |
203 | typedef uint32_t in_addr_t; |
204 | ||
fea681da | 205 | struct in_addr { |
9f8162f9 MK |
206 | in_addr_t s_addr; |
207 | }; | |
fea681da | 208 | .fi |
bd191423 | 209 | .in |
47297adb | 210 | .SH CONFORMING TO |
2b2581ee | 211 | 4.3BSD. |
054f5228 | 212 | .BR inet_addr () |
2b2581ee MK |
213 | and |
214 | .BR inet_ntoa () | |
215 | are specified in POSIX.1-2001. | |
054f5228 | 216 | .BR inet_aton () |