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