summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet_ntop.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/inet_ntop.3')
-rw-r--r--src/lib/libc/net/inet_ntop.3204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet_ntop.3 b/src/lib/libc/net/inet_ntop.3
new file mode 100644
index 0000000000..a5bd5076fe
--- /dev/null
+++ b/src/lib/libc/net/inet_ntop.3
@@ -0,0 +1,204 @@
1.\" $OpenBSD: inet_ntop.3,v 1.1 2014/04/19 11:18:01 guenther 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: April 19 2014 $
34.Dt INET_NTOP 3
35.Os
36.Sh NAME
37.Nm inet_ntop ,
38.Nm inet_pton
39.Nd convert Internet addresses between presentation and network formats
40.Sh SYNOPSIS
41.In arpa/inet.h
42.Ft const char *
43.Fn inet_ntop "int af" "const void * restrict src" "char * restrict dst" "socklen_t size"
44.Ft int
45.Fn inet_pton "int af" "const char * restrict src" "void * restrict dst"
46.Sh DESCRIPTION
47The
48.Fn inet_pton
49function converts a presentation format address (that is, printable form
50as held in a character string) to network format (usually a
51.Li struct in_addr
52or some other internal binary representation, in network byte order).
53It returns 1 if the address was valid for the specified address family;
540 if the address wasn't parseable in the specified address family; or \-1
55if some system error occurred (in which case
56.Va errno
57will have been set).
58This function is presently valid for
59.Dv AF_INET
60and
61.Dv AF_INET6 .
62.Pp
63The function
64.Fn inet_ntop
65converts an address from network format to presentation format.
66It returns
67.Dv NULL
68if a system
69error occurs (in which case,
70.Va errno
71will have been set), or it returns a pointer to the destination string.
72.Pp
73All Internet addresses are returned in network
74order (bytes ordered from left to right).
75.Sh INTERNET ADDRESSES (IP VERSION 4)
76Values must be specified using the standard dot notation:
77.Bd -literal -offset indent
78a.b.c.d
79.Ed
80.Pp
81All four parts must be decimal numbers between 0 and 255, inclusive.
82.Sh INTERNET ADDRESSES (IP VERSION 6)
83In order to support scoped IPv6 addresses,
84.Xr getaddrinfo 3
85and
86.Xr getnameinfo 3
87are recommended rather than the functions presented here.
88.Pp
89The presentation format of an IPv6 address is given in RFC 4291:
90.Pp
91There are three conventional forms for representing IPv6 addresses as
92text strings:
93.Bl -enum
94.It
95The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
96hexadecimal values of the eight 16-bit pieces of the address.
97Examples:
98.Bd -literal -offset indent
99FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
1001080:0:0:0:8:800:200C:417A
101.Ed
102.Pp
103Note that it is not necessary to write the leading zeros in an
104individual field, but there must be at least one numeral in
105every field (except for the case described in 2.).
106.It
107Due to the method of allocating certain styles of IPv6
108addresses, it will be common for addresses to contain long
109strings of zero bits.
110In order to make writing addresses
111containing zero bits easier, a special syntax is available to
112compress the zeros.
113The use of
114.Dq \&:\&:
115indicates multiple groups
116of 16 bits of zeros.
117The
118.Dq \&:\&:
119can only appear once in an
120address.
121The
122.Dq \&:\&:
123can also be used to compress the leading and/or trailing zeros in an address.
124.Pp
125For example the following addresses:
126.Bd -literal -offset indent
1271080:0:0:0:8:800:200C:417A a unicast address
128FF01:0:0:0:0:0:0:43 a multicast address
1290:0:0:0:0:0:0:1 the loopback address
1300:0:0:0:0:0:0:0 the unspecified addresses
131.Ed
132.Pp
133may be represented as:
134.Bd -literal -offset indent
1351080::8:800:200C:417A a unicast address
136FF01::43 a multicast address
137::1 the loopback address
138:: the unspecified addresses
139.Ed
140.It
141An alternative form that is sometimes more convenient when
142dealing with a mixed environment of IPv4 and IPv6 nodes is
143x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
144of the six high-order 16-bit pieces of the address, and the 'd's
145are the decimal values of the four low-order 8-bit pieces of the
146address (standard IPv4 representation).
147Examples:
148.Bd -literal -offset indent
1490:0:0:0:0:0:13.1.68.3
1500:0:0:0:0:FFFF:129.144.52.38
151.Ed
152.Pp
153or in compressed form:
154.Bd -literal -offset indent
155::13.1.68.3
156::FFFF:129.144.52.38
157.Ed
158.El
159.Sh SEE ALSO
160.Xr gethostbyname 3 ,
161.Xr inet_addr 3 ,
162.Xr inet_net 3 ,
163.Xr hosts 5
164.Sh STANDARDS
165The
166.Nm inet_ntop
167and
168.Nm inet_pton
169functions conform to the IETF IPv6 BSD API and address formatting
170specifications, as well as
171.St -p1003.1-2008 .
172.Sh HISTORY
173The
174.Nm inet_pton
175and
176.Nm inet_ntop
177functions appeared in BIND 4.9.4.
178.Sh CAVEATS
179Note that
180.Nm inet_pton
181does not accept 1-, 2-, or 3-part dotted addresses;
182all four parts must be specified and must be in decimal
183(and not octal or hexadecimal).
184This is a narrower input set than that accepted by
185.Nm inet_aton .
186.Pp
187.Rs
188.%A R. Gilligan
189.%A S. Thomson
190.%A J. Bound
191.%A J. McCann
192.%A W. Stevens
193.%D February 2003
194.%R RFC 3493
195.%T Basic Socket Interface Extensions for IPv6
196.Re
197.Pp
198.Rs
199.%A R. Hinden
200.%A S. Deering
201.%D February 2006
202.%R RFC 4291
203.%T IP Version 6 Addressing Architecture
204.Re