summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/inet.3')
-rw-r--r--src/lib/libc/net/inet.3345
1 files changed, 345 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3
new file mode 100644
index 0000000000..3f198ae8e0
--- /dev/null
+++ b/src/lib/libc/net/inet.3
@@ -0,0 +1,345 @@
1.\" $OpenBSD: inet.3,v 1.22 2008/12/09 19:38:38 otto Exp $
2.\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $
3.\"
4.\" Copyright (c) 1983, 1990, 1991, 1993
5.\" The Regents of the University of California. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" @(#)inet.3 8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: December 9 2008 $
34.Dt INET 3
35.Os
36.Sh NAME
37.Nm inet_addr ,
38.Nm inet_aton ,
39.Nm inet_lnaof ,
40.Nm inet_makeaddr ,
41.Nm inet_netof ,
42.Nm inet_network ,
43.Nm inet_ntoa ,
44.Nm inet_ntop ,
45.Nm inet_pton
46.Nd Internet address manipulation routines
47.Sh SYNOPSIS
48.Fd #include <sys/types.h>
49.Fd #include <sys/socket.h>
50.Fd #include <netinet/in.h>
51.Fd #include <arpa/inet.h>
52.Ft in_addr_t
53.Fn inet_addr "const char *cp"
54.Ft int
55.Fn inet_aton "const char *cp" "struct in_addr *addr"
56.Ft in_addr_t
57.Fn inet_lnaof "struct in_addr in"
58.Ft struct in_addr
59.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna"
60.Ft in_addr_t
61.Fn inet_netof "struct in_addr in"
62.Ft in_addr_t
63.Fn inet_network "const char *cp"
64.Ft char *
65.Fn inet_ntoa "struct in_addr in"
66.Ft const char *
67.Fn inet_ntop "int af" "const void *src" "char *dst" "socklen_t size"
68.Ft int
69.Fn inet_pton "int af" "const char *src" "void *dst"
70.Sh DESCRIPTION
71The routines
72.Fn inet_aton ,
73.Fn inet_addr ,
74and
75.Fn inet_network
76interpret character strings representing
77numbers expressed in the Internet standard
78.Dq dot
79notation.
80The
81.Fn inet_pton
82function converts a presentation format address (that is, printable form
83as held in a character string) to network format (usually a
84.Li struct in_addr
85or some other internal binary representation, in network byte order).
86It returns 1 if the address was valid for the specified address family;
870 if the address wasn't parseable in the specified address family; or \-1
88if some system error occurred (in which case
89.Va errno
90will have been set).
91This function is presently valid for
92.Dv AF_INET
93and
94.Dv AF_INET6 .
95The
96.Fn inet_aton
97routine interprets the specified character string as an Internet address,
98placing the address into the structure provided.
99It returns 1 if the string was successfully interpreted,
100or 0 if the string was invalid.
101The
102.Fn inet_addr
103and
104.Fn inet_network
105functions return numbers suitable for use
106as Internet addresses and Internet network
107numbers, respectively.
108.Pp
109The function
110.Fn inet_ntop
111converts an address from network format (usually a
112.Li struct in_addr
113or some other binary form, in network byte order) to presentation format
114(suitable for external display purposes).
115It returns
116.Dv NULL
117if a system
118error occurs (in which case,
119.Va errno
120will have been set), or it returns a pointer to the destination string.
121The routine
122.Fn inet_ntoa
123takes an Internet address and returns an
124ASCII string representing the address in dot notation.
125The routine
126.Fn inet_makeaddr
127takes an Internet network number and a local
128network address and constructs an Internet address
129from it.
130The routines
131.Fn inet_netof
132and
133.Fn inet_lnaof
134break apart Internet host addresses, returning
135the network number and local network address part,
136respectively.
137.Pp
138All Internet addresses are returned in network
139order (bytes ordered from left to right).
140All network numbers and local address parts are
141returned as machine format integer values.
142.Sh INTERNET ADDRESSES (IP VERSION 4)
143Values specified using dot notation take one of the following forms:
144.Bd -literal -offset indent
145a.b.c.d
146a.b.c
147a.b
148a
149.Ed
150.Pp
151When four parts are specified, each is interpreted
152as a byte of data and assigned, from left to right,
153to the four bytes of an Internet address.
154Note that when an Internet address is viewed as a 32-bit
155integer quantity on a system that uses little-endian
156byte order
157(such as the Intel 386, 486 and Pentium processors)
158the bytes referred to above appear as
159.Dq Li d.c.b.a .
160That is, little-endian bytes are ordered from right to left.
161.Pp
162When a three part address is specified, the last
163part is interpreted as a 16-bit quantity and placed
164in the rightmost two bytes of the network address.
165This makes the three part address format convenient
166for specifying Class B network addresses as
167.Dq Li 128.net.host .
168.Pp
169When a two part address is supplied, the last part
170is interpreted as a 24-bit quantity and placed in
171the rightmost three bytes of the network address.
172This makes the two part address format convenient
173for specifying Class A network addresses as
174.Dq Li net.host .
175.Pp
176When only one part is given, the value is stored
177directly in the network address without any byte
178rearrangement.
179.Pp
180All numbers supplied as
181.Dq parts
182in a dot notation
183may be decimal, octal, or hexadecimal, as specified
184in the C language (i.e., a leading 0x or 0X implies
185hexadecimal; a leading 0 implies octal;
186otherwise, the number is interpreted as decimal).
187.Sh INTERNET ADDRESSES (IP VERSION 6)
188In order to support scoped IPv6 addresses,
189.Xr getaddrinfo 3
190and
191.Xr getnameinfo 3
192are recommended rather than the functions presented here.
193.Pp
194The presentation format of an IPv6 address is given in RFC 2373:
195.Pp
196There are three conventional forms for representing IPv6 addresses as
197text strings:
198.Bl -enum
199.It
200The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
201hexadecimal values of the eight 16-bit pieces of the address.
202Examples:
203.Bd -literal -offset indent
204FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
2051080:0:0:0:8:800:200C:417A
206.Ed
207.Pp
208Note that it is not necessary to write the leading zeros in an
209individual field, but there must be at least one numeral in
210every field (except for the case described in 2.).
211.It
212Due to the method of allocating certain styles of IPv6
213addresses, it will be common for addresses to contain long
214strings of zero bits.
215In order to make writing addresses
216containing zero bits easier, a special syntax is available to
217compress the zeros.
218The use of
219.Dq \&:\&:
220indicates multiple groups
221of 16 bits of zeros.
222The
223.Dq \&:\&:
224can only appear once in an
225address.
226The
227.Dq \&:\&:
228can also be used to compress the leading and/or trailing zeros in an address.
229.Pp
230For example the following addresses:
231.Bd -literal -offset indent
2321080:0:0:0:8:800:200C:417A a unicast address
233FF01:0:0:0:0:0:0:43 a multicast address
2340:0:0:0:0:0:0:1 the loopback address
2350:0:0:0:0:0:0:0 the unspecified addresses
236.Ed
237.Pp
238may be represented as:
239.Bd -literal -offset indent
2401080::8:800:200C:417A a unicast address
241FF01::43 a multicast address
242::1 the loopback address
243:: the unspecified addresses
244.Ed
245.It
246An alternative form that is sometimes more convenient when
247dealing with a mixed environment of IPv4 and IPv6 nodes is
248x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
249of the six high-order 16-bit pieces of the address, and the 'd's
250are the decimal values of the four low-order 8-bit pieces of the
251address (standard IPv4 representation).
252Examples:
253.Bd -literal -offset indent
2540:0:0:0:0:0:13.1.68.3
2550:0:0:0:0:FFFF:129.144.52.38
256.Ed
257.Pp
258or in compressed form:
259.Bd -literal -offset indent
260::13.1.68.3
261::FFFF:129.144.52.38
262.Ed
263.El
264.Sh DIAGNOSTICS
265The constant
266.Dv INADDR_NONE
267is returned by
268.Fn inet_addr
269and
270.Fn inet_network
271for malformed requests.
272.Sh SEE ALSO
273.Xr byteorder 3 ,
274.Xr gethostbyname 3 ,
275.Xr getnetent 3 ,
276.Xr inet_net 3 ,
277.Xr hosts 5 ,
278.Xr networks 5
279.Rs
280.%R RFC 2373
281.%D July 1998
282.%T "IP Version 6 Addressing Architecture"
283.Re
284.Rs
285.%R RFC 3493
286.%D February 2003
287.%T "Basic Socket Interface Extensions for IPv6"
288.Re
289.Sh STANDARDS
290The
291.Nm inet_ntop
292and
293.Nm inet_pton
294functions conform to the IETF IPv6 BSD API and address formatting
295specifications.
296Note that
297.Nm inet_pton
298does not accept 1-, 2-, or 3-part dotted addresses; all four parts
299must be specified.
300This is a narrower input set than that accepted by
301.Nm inet_aton .
302.Sh HISTORY
303The
304.Nm inet_addr ,
305.Nm inet_network ,
306.Nm inet_makeaddr ,
307.Nm inet_lnaof ,
308and
309.Nm inet_netof
310functions appeared in
311.Bx 4.2 .
312The
313.Nm inet_aton
314and
315.Nm inet_ntoa
316functions appeared in
317.Bx 4.3 .
318The
319.Nm inet_pton
320and
321.Nm inet_ntop
322functions appeared in BIND 4.9.4.
323.Sh BUGS
324The value
325.Dv INADDR_NONE
326(0xffffffff) is a valid broadcast address, but
327.Fn inet_addr
328cannot return that value without indicating failure.
329Also,
330.Fn inet_addr
331should have been designed to return a
332.Li struct in_addr .
333The newer
334.Fn inet_aton
335function does not share these problems, and almost all existing code
336should be modified to use
337.Fn inet_aton
338instead.
339.Pp
340The problem of host byte ordering versus network byte ordering is
341confusing.
342.Pp
343The string returned by
344.Fn inet_ntoa
345resides in a static memory area.