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