diff options
Diffstat (limited to 'src/lib/libc/net/inet.3')
| -rw-r--r-- | src/lib/libc/net/inet.3 | 319 |
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 | ||
| 74 | The routines | ||
| 75 | .Fn inet_aton , | ||
| 76 | .Fn inet_addr | ||
| 77 | and | ||
| 78 | .Fn inet_network | ||
| 79 | interpret character strings representing | ||
| 80 | numbers expressed in the Internet standard | ||
| 81 | .Ql \&. | ||
| 82 | notation. | ||
| 83 | The | ||
| 84 | .Fn inet_pton | ||
| 85 | function converts a presentation format address (that is, printable form | ||
| 86 | as held in a character string) to network format (usually a | ||
| 87 | .Ft struct in_addr | ||
| 88 | or some other internal binary representation, in network byte order). It | ||
| 89 | returns 1 if the address was valid for the specified address family, or | ||
| 90 | 0 if the address wasn't parseable in the specified address family, or -1 | ||
| 91 | if some system error occurred (in which case | ||
| 92 | .Va errno | ||
| 93 | will have been set). This function is presently valid for AF_INET and | ||
| 94 | AF_INET6. The | ||
| 95 | .Fn inet_aton | ||
| 96 | routine interprets the specified character string as an Internet address, | ||
| 97 | placing the address into the structure provided. | ||
| 98 | It returns 1 if the string was successfully interpreted, | ||
| 99 | or 0 if the string is invalid. | ||
| 100 | The | ||
| 101 | .Fn inet_addr | ||
| 102 | and | ||
| 103 | .Fn inet_network | ||
| 104 | functions return numbers suitable for use | ||
| 105 | as Internet addresses and Internet network | ||
| 106 | numbers, respectively. | ||
| 107 | .Pp | ||
| 108 | The function | ||
| 109 | .Fn inet_ntop | ||
| 110 | converts an address from network format (usually a | ||
| 111 | .Ft struct in_addr | ||
| 112 | or some other binary form, in network byte order) to presentation format | ||
| 113 | (suitable for external display purposes). It returns NULL if a system | ||
| 114 | error occurs (in which case, | ||
| 115 | .Va errno | ||
| 116 | will have been set), or it returns a pointer to the destination string. | ||
| 117 | The routine | ||
| 118 | .Fn inet_ntoa | ||
| 119 | takes an Internet address and returns an | ||
| 120 | .Tn ASCII | ||
| 121 | string representing the address in | ||
| 122 | .Ql \&. | ||
| 123 | notation. The routine | ||
| 124 | .Fn inet_makeaddr | ||
| 125 | takes an Internet network number and a local | ||
| 126 | network address and constructs an Internet address | ||
| 127 | from it. The routines | ||
| 128 | .Fn inet_netof | ||
| 129 | and | ||
| 130 | .Fn inet_lnaof | ||
| 131 | break apart Internet host addresses, returning | ||
| 132 | the network number and local network address part, | ||
| 133 | respectively. | ||
| 134 | .Pp | ||
| 135 | All Internet addresses are returned in network | ||
| 136 | order (bytes ordered from left to right). | ||
| 137 | All network numbers and local address parts are | ||
| 138 | returned as machine format integer values. | ||
| 139 | .Sh INTERNET ADDRESSES (IP VERSION 4) | ||
| 140 | Values specified using the | ||
| 141 | .Ql \&. | ||
| 142 | notation take one | ||
| 143 | of the following forms: | ||
| 144 | .Bd -literal -offset indent | ||
| 145 | a.b.c.d | ||
| 146 | a.b.c | ||
| 147 | a.b | ||
| 148 | a | ||
| 149 | .Ed | ||
| 150 | .Pp | ||
| 151 | When four parts are specified, each is interpreted | ||
| 152 | as a byte of data and assigned, from left to right, | ||
| 153 | to the four bytes of an Internet address. Note | ||
| 154 | that when an Internet address is viewed as a 32-bit | ||
| 155 | integer quantity on a system that uses little-endian | ||
| 156 | byte order (such as the | ||
| 157 | .Tn Intel 386, 486 | ||
| 158 | and | ||
| 159 | .Tn Pentium | ||
| 160 | processors) the bytes referred to above appear as | ||
| 161 | .Dq Li d.c.b.a . | ||
| 162 | That is, little-endian bytes are ordered from right to left. | ||
| 163 | .Pp | ||
| 164 | When a three part address is specified, the last | ||
| 165 | part is interpreted as a 16-bit quantity and placed | ||
| 166 | in the right-most two bytes of the network address. | ||
| 167 | This makes the three part address format convenient | ||
| 168 | for specifying Class B network addresses as | ||
| 169 | .Dq Li 128.net.host . | ||
| 170 | .Pp | ||
| 171 | When a two part address is supplied, the last part | ||
| 172 | is interpreted as a 24-bit quantity and placed in | ||
| 173 | the right most three bytes of the network address. | ||
| 174 | This makes the two part address format convenient | ||
| 175 | for specifying Class A network addresses as | ||
| 176 | .Dq Li net.host . | ||
| 177 | .Pp | ||
| 178 | When only one part is given, the value is stored | ||
| 179 | directly in the network address without any byte | ||
| 180 | rearrangement. | ||
| 181 | .Pp | ||
| 182 | All numbers supplied as | ||
| 183 | .Dq parts | ||
| 184 | in a | ||
| 185 | .Ql \&. | ||
| 186 | notation | ||
| 187 | may be decimal, octal, or hexadecimal, as specified | ||
| 188 | in the C language (i.e., a leading 0x or 0X implies | ||
| 189 | hexadecimal; otherwise, a leading 0 implies octal; | ||
| 190 | otherwise, the number is interpreted as decimal). | ||
| 191 | .Sh INTERNET ADDRESSES (IP VERSION 6) | ||
| 192 | The presentation format of an IPv6 address is given in [RFC1884 2.2]: | ||
| 193 | .Pp | ||
| 194 | There are three conventional forms for representing IPv6 addresses as | ||
| 195 | text strings: | ||
| 196 | .Bl -enum | ||
| 197 | .It | ||
| 198 | The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the | ||
| 199 | hexadecimal values of the eight 16-bit pieces of the address. | ||
| 200 | Examples: | ||
| 201 | .Bd -literal -offset indent | ||
| 202 | FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 | ||
| 203 | 1080:0:0:0:8:800:200C:417A | ||
| 204 | .Ed | ||
| 205 | .Pp | ||
| 206 | Note that it is not necessary to write the leading zeros in an | ||
| 207 | individual field, but there must be at least one numeral in | ||
| 208 | every field (except for the case described in 2.). | ||
| 209 | .It | ||
| 210 | Due to the method of allocating certain styles of IPv6 | ||
| 211 | addresses, it will be common for addresses to contain long | ||
| 212 | strings of zero bits. In order to make writing addresses | ||
| 213 | .Pp | ||
| 214 | containing zero bits easier a special syntax is available to | ||
| 215 | compress the zeros. The use of ``::'' indicates multiple groups | ||
| 216 | of 16-bits of zeros. The ``::'' can only appear once in an | ||
| 217 | address. The ``::'' can also be used to compress the leading | ||
| 218 | and/or trailing zeros in an address. | ||
| 219 | .Pp | ||
| 220 | For example the following addresses: | ||
| 221 | .Bd -literal -offset indent | ||
| 222 | 1080:0:0:0:8:800:200C:417A a unicast address | ||
| 223 | FF01:0:0:0:0:0:0:43 a multicast address | ||
| 224 | 0:0:0:0:0:0:0:1 the loopback address | ||
| 225 | 0:0:0:0:0:0:0:0 the unspecified addresses | ||
| 226 | .Ed | ||
| 227 | .Pp | ||
| 228 | may be represented as: | ||
| 229 | .Bd -literal -offset indent | ||
| 230 | 1080::8:800:200C:417A a unicast address | ||
| 231 | FF01::43 a multicast address | ||
| 232 | ::1 the loopback address | ||
| 233 | :: the unspecified addresses | ||
| 234 | .Ed | ||
| 235 | .It | ||
| 236 | An alternative form that is sometimes more convenient when | ||
| 237 | dealing with a mixed environment of IPv4 and IPv6 nodes is | ||
| 238 | x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values | ||
| 239 | of the six high-order 16-bit pieces of the address, and the 'd's | ||
| 240 | are the decimal values of the four low-order 8-bit pieces of the | ||
| 241 | address (standard IPv4 representation). Examples: | ||
| 242 | .Bd -literal -offset indent | ||
| 243 | 0:0:0:0:0:0:13.1.68.3 | ||
| 244 | 0:0:0:0:0:FFFF:129.144.52.38 | ||
| 245 | .Ed | ||
| 246 | .Pp | ||
| 247 | or 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 | ||
| 254 | The constant | ||
| 255 | .Dv INADDR_NONE | ||
| 256 | is returned by | ||
| 257 | .Fn inet_addr | ||
| 258 | and | ||
| 259 | .Fn inet_network | ||
| 260 | for 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 | ||
| 269 | The | ||
| 270 | .Nm inet_ntop | ||
| 271 | and | ||
| 272 | .Nm inet_pton | ||
| 273 | functions conforms to the IETF IPng BSD API and address formatting | ||
| 274 | specifications. Note that | ||
| 275 | .Nm inet_pton | ||
| 276 | does not accept 1-, 2-, or 3-part dotted addresses; all four parts | ||
| 277 | must be specified. This is a narrower input set than that accepted by | ||
| 278 | .Nm inet_aton . | ||
| 279 | .Sh HISTORY | ||
| 280 | The | ||
| 281 | .Nm inet_addr , | ||
| 282 | .Nm inet_network , | ||
| 283 | .Nm inet_makeaddr , | ||
| 284 | .Nm inet_lnaof | ||
| 285 | and | ||
| 286 | .Nm inet_netof | ||
| 287 | functions appeared in | ||
| 288 | .Bx 4.2 . | ||
| 289 | The | ||
| 290 | .Nm inet_aton | ||
| 291 | and | ||
| 292 | .Nm inet_ntoa | ||
| 293 | functions appeared in | ||
| 294 | .Bx 4.3 . | ||
| 295 | The | ||
| 296 | .Nm inet_pton | ||
| 297 | and | ||
| 298 | .Nm inet_ntop | ||
| 299 | functions appeared in BIND 4.9.4. | ||
| 300 | .Sh BUGS | ||
| 301 | The value | ||
| 302 | .Dv INADDR_NONE | ||
| 303 | (0xffffffff) is a valid broadcast address, but | ||
| 304 | .Fn inet_addr | ||
| 305 | cannot return that value without indicating failure. | ||
| 306 | The newer | ||
| 307 | .Fn inet_aton | ||
| 308 | function does not share this problem. | ||
| 309 | .Pp | ||
| 310 | The problem of host byte ordering versus network byte ordering is | ||
| 311 | confusing. | ||
| 312 | .Pp | ||
| 313 | The string returned by | ||
| 314 | .Fn inet_ntoa | ||
| 315 | resides in a static memory area. | ||
| 316 | .Pp | ||
| 317 | .Fn inet_addr | ||
| 318 | should return a | ||
| 319 | .Fa "struct in_addr" . | ||
