summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libc/net/inet.3184
1 files changed, 154 insertions, 30 deletions
diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3
index db28804e32..2fb86cd927 100644
--- a/src/lib/libc/net/inet.3
+++ b/src/lib/libc/net/inet.3
@@ -1,4 +1,5 @@
1.\" $OpenBSD: inet.3,v 1.3 1997/04/05 21:13:10 millert Exp $ 1.\" $OpenBSD: inet.3,v 1.4 1997/06/23 04:01:11 millert 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.
@@ -31,36 +32,44 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 33.\" SUCH DAMAGE.
33.\" 34.\"
34.Dd June 4, 1993 35.\" @(#)inet.3 8.1 (Berkeley) 6/4/93
36.\"
37.Dd June 18, 1997
35.Dt INET 3 38.Dt INET 3
36.Os BSD 4.2 39.Os BSD 4.2
37.Sh NAME 40.Sh NAME
38.Nm inet_aton ,
39.Nm inet_addr , 41.Nm inet_addr ,
42.Nm inet_aton ,
43.Nm inet_lnaof ,
44.Nm inet_makeaddr ,
45.Nm inet_netof ,
40.Nm inet_network , 46.Nm inet_network ,
41.Nm inet_ntoa , 47.Nm inet_ntoa ,
42.Nm inet_makeaddr , 48.Nm inet_ntop ,
43.Nm inet_lnaof , 49.Nm inet_pton
44.Nm inet_netof
45.Nd Internet address manipulation routines 50.Nd Internet address manipulation routines
46.Sh SYNOPSIS 51.Sh SYNOPSIS
47.Fd #include <sys/socket.h> 52.Fd #include <sys/socket.h>
48.Fd #include <netinet/in.h> 53.Fd #include <netinet/in.h>
49.Fd #include <arpa/inet.h> 54.Fd #include <arpa/inet.h>
50.Ft int 55.Ft in_addr_t
51.Fn inet_aton "const char *cp" "struct in_addr *pin"
52.Ft in_addr_t
53.Fn inet_addr "const char *cp" 56.Fn inet_addr "const char *cp"
54.Ft in_addr_t 57.Ft int
58.Fn inet_aton "const char *cp" "struct in_addr *addr"
59.Ft in_addr_t
60.Fn inet_lnaof "struct in_addr in"
61.Ft struct in_addr
62.Fn inet_makeaddr "unsigned long net" "unsigned long lna"
63.Ft in_addr_t
64.Fn inet_netof "struct in_addr in"
65.Ft in_addr_t
55.Fn inet_network "const char *cp" 66.Fn inet_network "const char *cp"
56.Ft char * 67.Ft char *
57.Fn inet_ntoa "struct in_addr in" 68.Fn inet_ntoa "struct in_addr in"
58.Ft struct in_addr 69.Ft const char *
59.Fn inet_makeaddr "int net" "int lna" 70.Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size"
60.Ft in_addr_t 71.Ft int
61.Fn inet_lnaof "struct in_addr in" 72.Fn inet_pton "int af" "const char *src" "void *dst"
62.Ft in_addr_t
63.Fn inet_netof "struct in_addr in"
64.Sh DESCRIPTION 73.Sh DESCRIPTION
65The routines 74The routines
66.Fn inet_aton , 75.Fn inet_aton ,
@@ -72,6 +81,17 @@ numbers expressed in the Internet standard
72.Ql \&. 81.Ql \&.
73notation. 82notation.
74The 83The
84.Fn inet_pton
85function converts a presentation format address (that is, printable form
86as held in a character string) to network format (usually a
87.Ft struct in_addr
88or some other internal binary representation, in network byte order). It
89returns 1 if the address was valid for the specified address family, or
900 if the address wasn't parseable in the specified address family, or -1
91if some system error occurred (in which case
92.Va errno
93will have been set). This function is presently valid for AF_INET and
94AF_INET6. The
75.Fn inet_aton 95.Fn inet_aton
76routine interprets the specified character string as an Internet address, 96routine interprets the specified character string as an Internet address,
77placing the address into the structure provided. 97placing the address into the structure provided.
@@ -84,6 +104,16 @@ and
84functions return numbers suitable for use 104functions return numbers suitable for use
85as Internet addresses and Internet network 105as Internet addresses and Internet network
86numbers, respectively. 106numbers, respectively.
107.Pp
108The function
109.Fn inet_ntop
110converts an address from network format (usually a
111.Ft struct in_addr
112or some other binary form, in network byte order) to presentation format
113(suitable for external display purposes). It returns NULL if a system
114error occurs (in which case,
115.Va errno
116will have been set), or it returns a pointer to the destination string.
87The routine 117The routine
88.Fn inet_ntoa 118.Fn inet_ntoa
89takes an Internet address and returns an 119takes an Internet address and returns an
@@ -106,7 +136,7 @@ All Internet addresses are returned in network
106order (bytes ordered from left to right). 136order (bytes ordered from left to right).
107All network numbers and local address parts are 137All network numbers and local address parts are
108returned as machine format integer values. 138returned as machine format integer values.
109.Sh INTERNET ADDRESSES 139.Sh INTERNET ADDRESSES (IP VERSION 4)
110Values specified using the 140Values specified using the
111.Ql \&. 141.Ql \&.
112notation take one 142notation take one
@@ -122,15 +152,14 @@ When four parts are specified, each is interpreted
122as a byte of data and assigned, from left to right, 152as a byte of data and assigned, from left to right,
123to the four bytes of an Internet address. Note 153to the four bytes of an Internet address. Note
124that when an Internet address is viewed as a 32-bit 154that when an Internet address is viewed as a 32-bit
125integer quantity on the 155integer quantity on a system that uses little-endian
126.Tn VAX 156byte order (such as the
127the bytes referred to 157.Tn Intel 386, 486
128above appear as 158and
159.Tn Pentium
160processors) the bytes referred to above appear as
129.Dq Li d.c.b.a . 161.Dq Li d.c.b.a .
130That is, 162That is, little-endian bytes are ordered from right to left.
131.Tn VAX
132bytes are
133ordered from right to left.
134.Pp 163.Pp
135When a three part address is specified, the last 164When a three part address is specified, the last
136part is interpreted as a 16-bit quantity and placed 165part is interpreted as a 16-bit quantity and placed
@@ -159,6 +188,68 @@ may be decimal, octal, or hexadecimal, as specified
159in the C language (i.e., a leading 0x or 0X implies 188in the C language (i.e., a leading 0x or 0X implies
160hexadecimal; otherwise, a leading 0 implies octal; 189hexadecimal; otherwise, a leading 0 implies octal;
161otherwise, the number is interpreted as decimal). 190otherwise, the number is interpreted as decimal).
191.Sh INTERNET ADDRESSES (IP VERSION 6)
192The presentation format of an IPv6 address is given in [RFC1884 2.2]:
193.Pp
194There are three conventional forms for representing IPv6 addresses as
195text strings:
196.Bl -enum
197.It
198The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
199hexadecimal values of the eight 16-bit pieces of the address.
200Examples:
201.Bd -literal -offset indent
202FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
2031080:0:0:0:8:800:200C:417A
204.Ed
205.Pp
206Note that it is not necessary to write the leading zeros in an
207individual field, but there must be at least one numeral in
208every field (except for the case described in 2.).
209.It
210Due to the method of allocating certain styles of IPv6
211addresses, it will be common for addresses to contain long
212strings of zero bits. In order to make writing addresses
213.Pp
214containing zero bits easier a special syntax is available to
215compress the zeros. The use of ``::'' indicates multiple groups
216of 16-bits of zeros. The ``::'' can only appear once in an
217address. The ``::'' can also be used to compress the leading
218and/or trailing zeros in an address.
219.Pp
220For example the following addresses:
221.Bd -literal -offset indent
2221080:0:0:0:8:800:200C:417A a unicast address
223FF01:0:0:0:0:0:0:43 a multicast address
2240:0:0:0:0:0:0:1 the loopback address
2250:0:0:0:0:0:0:0 the unspecified addresses
226.Ed
227.Pp
228may be represented as:
229.Bd -literal -offset indent
2301080::8:800:200C:417A a unicast address
231FF01::43 a multicast address
232::1 the loopback address
233:: the unspecified addresses
234.Ed
235.It
236An alternative form that is sometimes more convenient when
237dealing with a mixed environment of IPv4 and IPv6 nodes is
238x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
239of the six high-order 16-bit pieces of the address, and the 'd's
240are the decimal values of the four low-order 8-bit pieces of the
241address (standard IPv4 representation). Examples:
242.Bd -literal -offset indent
2430:0:0:0:0:0:13.1.68.3
2440:0:0:0:0:FFFF:129.144.52.38
245.Ed
246.Pp
247or in compressed form:
248.Bd -literal -offset indent
249::13.1.68.3
250::FFFF:129.144.52.38
251.Ed
252.El
162.Sh DIAGNOSTICS 253.Sh DIAGNOSTICS
163The constant 254The constant
164.Dv INADDR_NONE 255.Dv INADDR_NONE
@@ -168,14 +259,44 @@ and
168.Fn inet_network 259.Fn inet_network
169for malformed requests. 260for malformed requests.
170.Sh SEE ALSO 261.Sh SEE ALSO
262.Xr byteorder 3 ,
171.Xr gethostbyname 3 , 263.Xr gethostbyname 3 ,
172.Xr getnetent 3 , 264.Xr getnetent 3 ,
265.Xr inet_net 3 ,
173.Xr hosts 5 , 266.Xr hosts 5 ,
174.Xr networks 5 , 267.Xr networks 5
268.Sh STANDARDS
269The
270.Nm inet_ntop
271and
272.Nm inet_pton
273functions conforms to the IETF IPng BSD API and address formatting
274specifications. Note that
275.Nm inet_pton
276does not accept 1-, 2-, or 3-part dotted addresses; all four parts
277must be specified. This is a narrower input set than that accepted by
278.Nm inet_aton .
175.Sh HISTORY 279.Sh HISTORY
176These 280The
177functions appeared in 281.Nm inet_addr ,
282.Nm inet_network ,
283.Nm inet_makeaddr ,
284.Nm inet_lnaof
285and
286.Nm inet_netof
287functions appeared in
178.Bx 4.2 . 288.Bx 4.2 .
289The
290.Nm inet_aton
291and
292.Nm inet_ntoa
293functions appeared in
294.Bx 4.3 .
295The
296.Nm inet_pton
297and
298.Nm inet_ntop
299functions appeared in BIND 4.9.4.
179.Sh BUGS 300.Sh BUGS
180The value 301The value
181.Dv INADDR_NONE 302.Dv INADDR_NONE
@@ -185,11 +306,14 @@ cannot return that value without indicating failure.
185The newer 306The newer
186.Fn inet_aton 307.Fn inet_aton
187function does not share this problem. 308function does not share this problem.
309.Pp
188The problem of host byte ordering versus network byte ordering is 310The problem of host byte ordering versus network byte ordering is
189confusing. 311confusing.
312.Pp
190The string returned by 313The string returned by
191.Fn inet_ntoa 314.Fn inet_ntoa
192resides in a static memory area. 315resides in a static memory area.
193.Pp 316.Pp
194Inet_addr should return a 317.Fn inet_addr
195.Fa struct in_addr . 318should return a
319.Fa "struct in_addr" .