summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet.3
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1998-10-19 21:47:13 +0000
committercvs2svn <admin@example.com>1998-10-19 21:47:13 +0000
commitf954a53a9a7dced3fb4c80b1e8dd267981ae025d (patch)
treec667406046ddb1efca5ed4316b02e43494241660 /src/lib/libc/net/inet.3
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-OPENBSD_2_4.tar.gz
openbsd-OPENBSD_2_4.tar.bz2
openbsd-OPENBSD_2_4.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_4'.OPENBSD_2_4
Diffstat (limited to 'src/lib/libc/net/inet.3')
-rw-r--r--src/lib/libc/net/inet.3319
1 files changed, 319 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..2fb86cd927
--- /dev/null
+++ b/src/lib/libc/net/inet.3
@@ -0,0 +1,319 @@
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 $
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. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by the University of
18.\" California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\" may be used to endorse or promote products derived from this software
21.\" without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\" @(#)inet.3 8.1 (Berkeley) 6/4/93
36.\"
37.Dd June 18, 1997
38.Dt INET 3
39.Os BSD 4.2
40.Sh NAME
41.Nm inet_addr ,
42.Nm inet_aton ,
43.Nm inet_lnaof ,
44.Nm inet_makeaddr ,
45.Nm inet_netof ,
46.Nm inet_network ,
47.Nm inet_ntoa ,
48.Nm inet_ntop ,
49.Nm inet_pton
50.Nd Internet address manipulation routines
51.Sh SYNOPSIS
52.Fd #include <sys/socket.h>
53.Fd #include <netinet/in.h>
54.Fd #include <arpa/inet.h>
55.Ft in_addr_t
56.Fn inet_addr "const char *cp"
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
66.Fn inet_network "const char *cp"
67.Ft char *
68.Fn inet_ntoa "struct in_addr in"
69.Ft const char *
70.Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size"
71.Ft int
72.Fn inet_pton "int af" "const char *src" "void *dst"
73.Sh DESCRIPTION
74The routines
75.Fn inet_aton ,
76.Fn inet_addr
77and
78.Fn inet_network
79interpret character strings representing
80numbers expressed in the Internet standard
81.Ql \&.
82notation.
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
95.Fn inet_aton
96routine interprets the specified character string as an Internet address,
97placing the address into the structure provided.
98It returns 1 if the string was successfully interpreted,
99or 0 if the string is invalid.
100The
101.Fn inet_addr
102and
103.Fn inet_network
104functions return numbers suitable for use
105as Internet addresses and Internet network
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.
117The routine
118.Fn inet_ntoa
119takes an Internet address and returns an
120.Tn ASCII
121string representing the address in
122.Ql \&.
123notation. The routine
124.Fn inet_makeaddr
125takes an Internet network number and a local
126network address and constructs an Internet address
127from it. The routines
128.Fn inet_netof
129and
130.Fn inet_lnaof
131break apart Internet host addresses, returning
132the network number and local network address part,
133respectively.
134.Pp
135All Internet addresses are returned in network
136order (bytes ordered from left to right).
137All network numbers and local address parts are
138returned as machine format integer values.
139.Sh INTERNET ADDRESSES (IP VERSION 4)
140Values specified using the
141.Ql \&.
142notation take one
143of 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. Note
154that when an Internet address is viewed as a 32-bit
155integer quantity on a system that uses little-endian
156byte order (such as the
157.Tn Intel 386, 486
158and
159.Tn Pentium
160processors) the bytes referred to above appear as
161.Dq Li d.c.b.a .
162That is, little-endian bytes are ordered from right to left.
163.Pp
164When a three part address is specified, the last
165part is interpreted as a 16-bit quantity and placed
166in the right-most two bytes of the network address.
167This makes the three part address format convenient
168for specifying Class B network addresses as
169.Dq Li 128.net.host .
170.Pp
171When a two part address is supplied, the last part
172is interpreted as a 24-bit quantity and placed in
173the right most three bytes of the network address.
174This makes the two part address format convenient
175for specifying Class A network addresses as
176.Dq Li net.host .
177.Pp
178When only one part is given, the value is stored
179directly in the network address without any byte
180rearrangement.
181.Pp
182All numbers supplied as
183.Dq parts
184in a
185.Ql \&.
186notation
187may be decimal, octal, or hexadecimal, as specified
188in the C language (i.e., a leading 0x or 0X implies
189hexadecimal; otherwise, a leading 0 implies octal;
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
253.Sh DIAGNOSTICS
254The constant
255.Dv INADDR_NONE
256is returned by
257.Fn inet_addr
258and
259.Fn inet_network
260for malformed requests.
261.Sh SEE ALSO
262.Xr byteorder 3 ,
263.Xr gethostbyname 3 ,
264.Xr getnetent 3 ,
265.Xr inet_net 3 ,
266.Xr hosts 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 .
279.Sh HISTORY
280The
281.Nm inet_addr ,
282.Nm inet_network ,
283.Nm inet_makeaddr ,
284.Nm inet_lnaof
285and
286.Nm inet_netof
287functions appeared in
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.
300.Sh BUGS
301The value
302.Dv INADDR_NONE
303(0xffffffff) is a valid broadcast address, but
304.Fn inet_addr
305cannot return that value without indicating failure.
306The newer
307.Fn inet_aton
308function does not share this problem.
309.Pp
310The problem of host byte ordering versus network byte ordering is
311confusing.
312.Pp
313The string returned by
314.Fn inet_ntoa
315resides in a static memory area.
316.Pp
317.Fn inet_addr
318should return a
319.Fa "struct in_addr" .