1 .\" $NetBSD: inet.3,v 1.1 2004/05/20 23:13:02 christos Exp $
3 .\" Copyright (c) 1983, 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)inet.3 8.1 (Berkeley) 6/4/93
48 .Nd Internet address manipulation routines
54 .Fn inet_addr "const char *cp"
56 .Fn inet_aton "const char *cp" "struct in_addr *addr"
58 .Fn inet_lnaof "struct in_addr in"
60 .Fn inet_makeaddr "in_addr_t net" "in_addr_t lna"
62 .Fn inet_netof "struct in_addr in"
64 .Fn inet_network "const char *cp"
66 .Fn inet_ntoa "struct in_addr in"
68 .Fn inet_ntop "int af" "const void * restrict src" "char * restrict dst" "socklen_t size"
70 .Fn inet_pton "int af" "const char * restrict src" "void * restrict dst"
77 interpret character strings representing
78 numbers expressed in the Internet standard
84 function converts a presentation format address (that is, printable form
85 as held in a character string) to network format (usually a
87 or some other internal binary representation, in network byte order).
88 It returns 1 if the address was valid for the specified address family, or
89 0 if the address wasn't parsable in the specified address family, or -1
90 if some system error occurred (in which case
93 This function is presently valid for
100 routine interprets the specified character string as an Internet address,
101 placing the address into the structure provided.
102 It returns 1 if the string was successfully interpreted,
103 or 0 if the string is invalid.
109 functions return numbers suitable for use
110 as Internet addresses and Internet network
111 numbers, respectively.
115 converts an address from network format (usually a
117 or some other binary form, in network byte order) to presentation format
118 (suitable for external display purposes).
119 It returns NULL if a system error occurs (in which case,
121 will have been set), or it returns a pointer to the destination string.
125 takes an Internet address and returns an
127 string representing the address in
133 takes an Internet network number and a local network address (both in
134 host order) and constructs an Internet address from it.
135 Note that to convert only a single value to a
137 form that value should be passed as the first parameter and
139 should be given for the second parameter.
145 break apart Internet host addresses, returning the network number and
146 local network address part, respectively (both in host order).
148 All Internet addresses are returned in network
149 order (bytes ordered from left to right).
150 All network numbers and local address parts are
151 returned as machine format integer values.
152 .Sh INTERNET ADDRESSES (IP VERSION 4)
153 Values specified using the
156 of the following forms:
157 .Bd -literal -offset indent
164 When four parts are specified, each is interpreted
165 as a byte of data and assigned, from left to right,
166 to the four bytes of an Internet address.
167 Note that when an Internet address is viewed as a 32-bit
168 integer quantity on a system that uses little-endian
173 processors) the bytes referred to above appear as
175 That is, little-endian bytes are ordered from right to left.
177 When a three part address is specified, the last
178 part is interpreted as a 16-bit quantity and placed
179 in the right-most two bytes of the network address.
180 This makes the three part address format convenient
181 for specifying Class B network addresses as
182 .Dq Li 128.net.host .
184 When a two part address is supplied, the last part
185 is interpreted as a 24-bit quantity and placed in
186 the right most three bytes of the network address.
187 This makes the two part address format convenient
188 for specifying Class A network addresses as
191 When only one part is given, the value is stored
192 directly in the network address without any byte
195 All numbers supplied as
200 may be decimal, octal, or hexadecimal, as specified
201 in the C language (i.e., a leading 0x or 0X implies
202 hexadecimal; otherwise, a leading 0 implies octal;
203 otherwise, the number is interpreted as decimal).
204 .Sh INTERNET ADDRESSES (IP VERSION 6)
205 In order to support scoped IPv6 addresses,
210 is recommended rather than the functions presented here.
212 The presentation format of an IPv6 address is given in RFC 2373:
214 There are three conventional forms for representing IPv6 addresses as
218 The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
219 hexadecimal values of the eight 16-bit pieces of the address.
221 .Bd -literal -offset indent
222 FEDC:BA98:7654:3210:FEDC:BA98:7654:3210
223 1080:0:0:0:8:800:200C:417A
226 Note that it is not necessary to write the leading zeros in an
227 individual field, but there must be at least one numeral in
228 every field (except for the case described in 2).
230 Due to the method of allocating certain styles of IPv6
231 addresses, it will be common for addresses to contain long
232 strings of zero bits.
233 In order to make writing addresses
234 containing zero bits easier, a special syntax is available to
236 The use of ``::'' indicates multiple groups of 16-bits of zeros.
237 The ``::'' can only appear once in an address.
238 The ``::'' can also be used to compress the leading
239 and/or trailing zeros in an address.
241 For example the following addresses:
242 .Bd -literal -offset indent
243 1080:0:0:0:8:800:200C:417A a unicast address
244 FF01:0:0:0:0:0:0:43 a multicast address
245 0:0:0:0:0:0:0:1 the loopback address
246 0:0:0:0:0:0:0:0 the unspecified addresses
249 may be represented as:
250 .Bd -literal -offset indent
251 1080::8:800:200C:417A a unicast address
252 FF01::43 a multicast address
253 ::1 the loopback address
254 :: the unspecified addresses
257 An alternative form that is sometimes more convenient when
258 dealing with a mixed environment of IPv4 and IPv6 nodes is
259 x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
260 of the six high-order 16-bit pieces of the address, and the 'd's
261 are the decimal values of the four low-order 8-bit pieces of the
262 address (standard IPv4 representation).
264 .Bd -literal -offset indent
265 0:0:0:0:0:0:13.1.68.3
266 0:0:0:0:0:FFFF:129.144.52.38
269 or in compressed form:
270 .Bd -literal -offset indent
282 for malformed requests.
285 .Xr gethostbyname 3 ,
293 .%T "IP Version 6 Addressing Architecture"
298 .%T "Basic Socket Interface Extensions for IPv6"
309 does not accept 1-, 2-, or 3-part dotted addresses; all four parts
311 This is a narrower input set than that accepted by
321 functions appeared in
323 They were changed to use
333 functions appeared in
339 functions appeared in BIND 4.9.4 and thence
346 (0xffffffff) is a valid broadcast address, but
348 cannot return that value without indicating failure.
351 function does not share this problem.
353 The problem of host byte ordering versus network byte ordering is
356 The string returned by
358 resides in a static memory area.
362 .Fa "struct in_addr" .