diff options
Diffstat (limited to 'src/lib/libc/net/inet.3')
| -rw-r--r-- | src/lib/libc/net/inet.3 | 264 |
1 files changed, 206 insertions, 58 deletions
diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3 index 49bac97e96..3f198ae8e0 100644 --- a/src/lib/libc/net/inet.3 +++ b/src/lib/libc/net/inet.3 | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | .\" $NetBSD: inet.3,v 1.4 1995/02/27 09:45:26 chopps Exp $ | 1 | .\" $OpenBSD: inet.3,v 1.22 2008/12/09 19:38:38 otto 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. |
| @@ -11,11 +12,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 12 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 13 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 14 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 15 | .\" 3. Neither the name of the University nor the names of its contributors |
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | 16 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 17 | .\" without specific prior written permission. |
| 21 | .\" | 18 | .\" |
| @@ -33,52 +30,74 @@ | |||
| 33 | .\" | 30 | .\" |
| 34 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 | 31 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 |
| 35 | .\" | 32 | .\" |
| 36 | .Dd June 4, 1993 | 33 | .Dd $Mdocdate: December 9 2008 $ |
| 37 | .Dt INET 3 | 34 | .Dt INET 3 |
| 38 | .Os BSD 4.2 | 35 | .Os |
| 39 | .Sh NAME | 36 | .Sh NAME |
| 40 | .Nm inet_aton , | ||
| 41 | .Nm inet_addr , | 37 | .Nm inet_addr , |
| 38 | .Nm inet_aton , | ||
| 39 | .Nm inet_lnaof , | ||
| 40 | .Nm inet_makeaddr , | ||
| 41 | .Nm inet_netof , | ||
| 42 | .Nm inet_network , | 42 | .Nm inet_network , |
| 43 | .Nm inet_ntoa , | 43 | .Nm inet_ntoa , |
| 44 | .Nm inet_makeaddr , | 44 | .Nm inet_ntop , |
| 45 | .Nm inet_lnaof , | 45 | .Nm inet_pton |
| 46 | .Nm inet_netof | ||
| 47 | .Nd Internet address manipulation routines | 46 | .Nd Internet address manipulation routines |
| 48 | .Sh SYNOPSIS | 47 | .Sh SYNOPSIS |
| 48 | .Fd #include <sys/types.h> | ||
| 49 | .Fd #include <sys/socket.h> | 49 | .Fd #include <sys/socket.h> |
| 50 | .Fd #include <netinet/in.h> | 50 | .Fd #include <netinet/in.h> |
| 51 | .Fd #include <arpa/inet.h> | 51 | .Fd #include <arpa/inet.h> |
| 52 | .Ft int | 52 | .Ft in_addr_t |
| 53 | .Fn inet_aton "const char *cp" "struct in_addr *pin" | ||
| 54 | .Ft unsigned long | ||
| 55 | .Fn inet_addr "const char *cp" | 53 | .Fn inet_addr "const char *cp" |
| 56 | .Ft unsigned long | 54 | .Ft int |
| 55 | .Fn inet_aton "const char *cp" "struct in_addr *addr" | ||
| 56 | .Ft in_addr_t | ||
| 57 | .Fn inet_lnaof "struct in_addr in" | ||
| 58 | .Ft struct in_addr | ||
| 59 | .Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" | ||
| 60 | .Ft in_addr_t | ||
| 61 | .Fn inet_netof "struct in_addr in" | ||
| 62 | .Ft in_addr_t | ||
| 57 | .Fn inet_network "const char *cp" | 63 | .Fn inet_network "const char *cp" |
| 58 | .Ft char * | 64 | .Ft char * |
| 59 | .Fn inet_ntoa "struct in_addr in" | 65 | .Fn inet_ntoa "struct in_addr in" |
| 60 | .Ft struct in_addr | 66 | .Ft const char * |
| 61 | .Fn inet_makeaddr "int net" "int lna" | 67 | .Fn inet_ntop "int af" "const void *src" "char *dst" "socklen_t size" |
| 62 | .Ft unsigned long | 68 | .Ft int |
| 63 | .Fn inet_lnaof "struct in_addr in" | 69 | .Fn inet_pton "int af" "const char *src" "void *dst" |
| 64 | .Ft unsigned long | ||
| 65 | .Fn inet_netof "struct in_addr in" | ||
| 66 | .Sh DESCRIPTION | 70 | .Sh DESCRIPTION |
| 67 | The routines | 71 | The routines |
| 68 | .Fn inet_aton , | 72 | .Fn inet_aton , |
| 69 | .Fn inet_addr | 73 | .Fn inet_addr , |
| 70 | and | 74 | and |
| 71 | .Fn inet_network | 75 | .Fn inet_network |
| 72 | interpret character strings representing | 76 | interpret character strings representing |
| 73 | numbers expressed in the Internet standard | 77 | numbers expressed in the Internet standard |
| 74 | .Ql \&. | 78 | .Dq dot |
| 75 | notation. | 79 | notation. |
| 76 | The | 80 | The |
| 81 | .Fn inet_pton | ||
| 82 | function converts a presentation format address (that is, printable form | ||
| 83 | as held in a character string) to network format (usually a | ||
| 84 | .Li struct in_addr | ||
| 85 | or some other internal binary representation, in network byte order). | ||
| 86 | It returns 1 if the address was valid for the specified address family; | ||
| 87 | 0 if the address wasn't parseable in the specified address family; or \-1 | ||
| 88 | if some system error occurred (in which case | ||
| 89 | .Va errno | ||
| 90 | will have been set). | ||
| 91 | This function is presently valid for | ||
| 92 | .Dv AF_INET | ||
| 93 | and | ||
| 94 | .Dv AF_INET6 . | ||
| 95 | The | ||
| 77 | .Fn inet_aton | 96 | .Fn inet_aton |
| 78 | routine interprets the specified character string as an Internet address, | 97 | routine interprets the specified character string as an Internet address, |
| 79 | placing the address into the structure provided. | 98 | placing the address into the structure provided. |
| 80 | It returns 1 if the string was successfully interpreted, | 99 | It returns 1 if the string was successfully interpreted, |
| 81 | or 0 if the string is invalid. | 100 | or 0 if the string was invalid. |
| 82 | The | 101 | The |
| 83 | .Fn inet_addr | 102 | .Fn inet_addr |
| 84 | and | 103 | and |
| @@ -86,17 +105,29 @@ and | |||
| 86 | functions return numbers suitable for use | 105 | functions return numbers suitable for use |
| 87 | as Internet addresses and Internet network | 106 | as Internet addresses and Internet network |
| 88 | numbers, respectively. | 107 | numbers, respectively. |
| 108 | .Pp | ||
| 109 | The function | ||
| 110 | .Fn inet_ntop | ||
| 111 | converts an address from network format (usually a | ||
| 112 | .Li struct in_addr | ||
| 113 | or some other binary form, in network byte order) to presentation format | ||
| 114 | (suitable for external display purposes). | ||
| 115 | It returns | ||
| 116 | .Dv NULL | ||
| 117 | if a system | ||
| 118 | error occurs (in which case, | ||
| 119 | .Va errno | ||
| 120 | will have been set), or it returns a pointer to the destination string. | ||
| 89 | The routine | 121 | The routine |
| 90 | .Fn inet_ntoa | 122 | .Fn inet_ntoa |
| 91 | takes an Internet address and returns an | 123 | takes an Internet address and returns an |
| 92 | .Tn ASCII | 124 | ASCII string representing the address in dot notation. |
| 93 | string representing the address in | 125 | The routine |
| 94 | .Ql \&. | ||
| 95 | notation. The routine | ||
| 96 | .Fn inet_makeaddr | 126 | .Fn inet_makeaddr |
| 97 | takes an Internet network number and a local | 127 | takes an Internet network number and a local |
| 98 | network address and constructs an Internet address | 128 | network address and constructs an Internet address |
| 99 | from it. The routines | 129 | from it. |
| 130 | The routines | ||
| 100 | .Fn inet_netof | 131 | .Fn inet_netof |
| 101 | and | 132 | and |
| 102 | .Fn inet_lnaof | 133 | .Fn inet_lnaof |
| @@ -108,11 +139,8 @@ All Internet addresses are returned in network | |||
| 108 | order (bytes ordered from left to right). | 139 | order (bytes ordered from left to right). |
| 109 | All network numbers and local address parts are | 140 | All network numbers and local address parts are |
| 110 | returned as machine format integer values. | 141 | returned as machine format integer values. |
| 111 | .Sh INTERNET ADDRESSES | 142 | .Sh INTERNET ADDRESSES (IP VERSION 4) |
| 112 | Values specified using the | 143 | Values specified using dot notation take one of the following forms: |
| 113 | .Ql \&. | ||
| 114 | notation take one | ||
| 115 | of the following forms: | ||
| 116 | .Bd -literal -offset indent | 144 | .Bd -literal -offset indent |
| 117 | a.b.c.d | 145 | a.b.c.d |
| 118 | a.b.c | 146 | a.b.c |
| @@ -122,28 +150,25 @@ a | |||
| 122 | .Pp | 150 | .Pp |
| 123 | When four parts are specified, each is interpreted | 151 | When four parts are specified, each is interpreted |
| 124 | as a byte of data and assigned, from left to right, | 152 | as a byte of data and assigned, from left to right, |
| 125 | to the four bytes of an Internet address. Note | 153 | to the four bytes of an Internet address. |
| 126 | that when an Internet address is viewed as a 32-bit | 154 | Note that when an Internet address is viewed as a 32-bit |
| 127 | integer quantity on the | 155 | integer quantity on a system that uses little-endian |
| 128 | .Tn VAX | 156 | byte order |
| 129 | the bytes referred to | 157 | (such as the Intel 386, 486 and Pentium processors) |
| 130 | above appear as | 158 | the bytes referred to above appear as |
| 131 | .Dq Li d.c.b.a . | 159 | .Dq Li d.c.b.a . |
| 132 | That is, | 160 | That is, little-endian bytes are ordered from right to left. |
| 133 | .Tn VAX | ||
| 134 | bytes are | ||
| 135 | ordered from right to left. | ||
| 136 | .Pp | 161 | .Pp |
| 137 | When a three part address is specified, the last | 162 | When a three part address is specified, the last |
| 138 | part is interpreted as a 16-bit quantity and placed | 163 | part is interpreted as a 16-bit quantity and placed |
| 139 | in the right-most two bytes of the network address. | 164 | in the rightmost two bytes of the network address. |
| 140 | This makes the three part address format convenient | 165 | This makes the three part address format convenient |
| 141 | for specifying Class B network addresses as | 166 | for specifying Class B network addresses as |
| 142 | .Dq Li 128.net.host . | 167 | .Dq Li 128.net.host . |
| 143 | .Pp | 168 | .Pp |
| 144 | When a two part address is supplied, the last part | 169 | When a two part address is supplied, the last part |
| 145 | is interpreted as a 24-bit quantity and placed in | 170 | is interpreted as a 24-bit quantity and placed in |
| 146 | the right most three bytes of the network address. | 171 | the rightmost three bytes of the network address. |
| 147 | This makes the two part address format convenient | 172 | This makes the two part address format convenient |
| 148 | for specifying Class A network addresses as | 173 | for specifying Class A network addresses as |
| 149 | .Dq Li net.host . | 174 | .Dq Li net.host . |
| @@ -154,13 +179,88 @@ rearrangement. | |||
| 154 | .Pp | 179 | .Pp |
| 155 | All numbers supplied as | 180 | All numbers supplied as |
| 156 | .Dq parts | 181 | .Dq parts |
| 157 | in a | 182 | in a dot notation |
| 158 | .Ql \&. | ||
| 159 | notation | ||
| 160 | may be decimal, octal, or hexadecimal, as specified | 183 | may be decimal, octal, or hexadecimal, as specified |
| 161 | in the C language (i.e., a leading 0x or 0X implies | 184 | in the C language (i.e., a leading 0x or 0X implies |
| 162 | hexadecimal; otherwise, a leading 0 implies octal; | 185 | hexadecimal; a leading 0 implies octal; |
| 163 | otherwise, the number is interpreted as decimal). | 186 | otherwise, the number is interpreted as decimal). |
| 187 | .Sh INTERNET ADDRESSES (IP VERSION 6) | ||
| 188 | In order to support scoped IPv6 addresses, | ||
| 189 | .Xr getaddrinfo 3 | ||
| 190 | and | ||
| 191 | .Xr getnameinfo 3 | ||
| 192 | are recommended rather than the functions presented here. | ||
| 193 | .Pp | ||
| 194 | The presentation format of an IPv6 address is given in RFC 2373: | ||
| 195 | .Pp | ||
| 196 | There are three conventional forms for representing IPv6 addresses as | ||
| 197 | text strings: | ||
| 198 | .Bl -enum | ||
| 199 | .It | ||
| 200 | The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the | ||
| 201 | hexadecimal values of the eight 16-bit pieces of the address. | ||
| 202 | Examples: | ||
| 203 | .Bd -literal -offset indent | ||
| 204 | FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 | ||
| 205 | 1080:0:0:0:8:800:200C:417A | ||
| 206 | .Ed | ||
| 207 | .Pp | ||
| 208 | Note that it is not necessary to write the leading zeros in an | ||
| 209 | individual field, but there must be at least one numeral in | ||
| 210 | every field (except for the case described in 2.). | ||
| 211 | .It | ||
| 212 | Due to the method of allocating certain styles of IPv6 | ||
| 213 | addresses, it will be common for addresses to contain long | ||
| 214 | strings of zero bits. | ||
| 215 | In order to make writing addresses | ||
| 216 | containing zero bits easier, a special syntax is available to | ||
| 217 | compress the zeros. | ||
| 218 | The use of | ||
| 219 | .Dq \&:\&: | ||
| 220 | indicates multiple groups | ||
| 221 | of 16 bits of zeros. | ||
| 222 | The | ||
| 223 | .Dq \&:\&: | ||
| 224 | can only appear once in an | ||
| 225 | address. | ||
| 226 | The | ||
| 227 | .Dq \&:\&: | ||
| 228 | can also be used to compress the leading and/or trailing zeros in an address. | ||
| 229 | .Pp | ||
| 230 | For example the following addresses: | ||
| 231 | .Bd -literal -offset indent | ||
| 232 | 1080:0:0:0:8:800:200C:417A a unicast address | ||
| 233 | FF01:0:0:0:0:0:0:43 a multicast address | ||
| 234 | 0:0:0:0:0:0:0:1 the loopback address | ||
| 235 | 0:0:0:0:0:0:0:0 the unspecified addresses | ||
| 236 | .Ed | ||
| 237 | .Pp | ||
| 238 | may be represented as: | ||
| 239 | .Bd -literal -offset indent | ||
| 240 | 1080::8:800:200C:417A a unicast address | ||
| 241 | FF01::43 a multicast address | ||
| 242 | ::1 the loopback address | ||
| 243 | :: the unspecified addresses | ||
| 244 | .Ed | ||
| 245 | .It | ||
| 246 | An alternative form that is sometimes more convenient when | ||
| 247 | dealing with a mixed environment of IPv4 and IPv6 nodes is | ||
| 248 | x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values | ||
| 249 | of the six high-order 16-bit pieces of the address, and the 'd's | ||
| 250 | are the decimal values of the four low-order 8-bit pieces of the | ||
| 251 | address (standard IPv4 representation). | ||
| 252 | Examples: | ||
| 253 | .Bd -literal -offset indent | ||
| 254 | 0:0:0:0:0:0:13.1.68.3 | ||
| 255 | 0:0:0:0:0:FFFF:129.144.52.38 | ||
| 256 | .Ed | ||
| 257 | .Pp | ||
| 258 | or in compressed form: | ||
| 259 | .Bd -literal -offset indent | ||
| 260 | ::13.1.68.3 | ||
| 261 | ::FFFF:129.144.52.38 | ||
| 262 | .Ed | ||
| 263 | .El | ||
| 164 | .Sh DIAGNOSTICS | 264 | .Sh DIAGNOSTICS |
| 165 | The constant | 265 | The constant |
| 166 | .Dv INADDR_NONE | 266 | .Dv INADDR_NONE |
| @@ -170,28 +270,76 @@ and | |||
| 170 | .Fn inet_network | 270 | .Fn inet_network |
| 171 | for malformed requests. | 271 | for malformed requests. |
| 172 | .Sh SEE ALSO | 272 | .Sh SEE ALSO |
| 273 | .Xr byteorder 3 , | ||
| 173 | .Xr gethostbyname 3 , | 274 | .Xr gethostbyname 3 , |
| 174 | .Xr getnetent 3 , | 275 | .Xr getnetent 3 , |
| 276 | .Xr inet_net 3 , | ||
| 175 | .Xr hosts 5 , | 277 | .Xr hosts 5 , |
| 176 | .Xr networks 5 , | 278 | .Xr networks 5 |
| 279 | .Rs | ||
| 280 | .%R RFC 2373 | ||
| 281 | .%D July 1998 | ||
| 282 | .%T "IP Version 6 Addressing Architecture" | ||
| 283 | .Re | ||
| 284 | .Rs | ||
| 285 | .%R RFC 3493 | ||
| 286 | .%D February 2003 | ||
| 287 | .%T "Basic Socket Interface Extensions for IPv6" | ||
| 288 | .Re | ||
| 289 | .Sh STANDARDS | ||
| 290 | The | ||
| 291 | .Nm inet_ntop | ||
| 292 | and | ||
| 293 | .Nm inet_pton | ||
| 294 | functions conform to the IETF IPv6 BSD API and address formatting | ||
| 295 | specifications. | ||
| 296 | Note that | ||
| 297 | .Nm inet_pton | ||
| 298 | does not accept 1-, 2-, or 3-part dotted addresses; all four parts | ||
| 299 | must be specified. | ||
| 300 | This is a narrower input set than that accepted by | ||
| 301 | .Nm inet_aton . | ||
| 177 | .Sh HISTORY | 302 | .Sh HISTORY |
| 178 | These | 303 | The |
| 179 | functions appeared in | 304 | .Nm inet_addr , |
| 305 | .Nm inet_network , | ||
| 306 | .Nm inet_makeaddr , | ||
| 307 | .Nm inet_lnaof , | ||
| 308 | and | ||
| 309 | .Nm inet_netof | ||
| 310 | functions appeared in | ||
| 180 | .Bx 4.2 . | 311 | .Bx 4.2 . |
| 312 | The | ||
| 313 | .Nm inet_aton | ||
| 314 | and | ||
| 315 | .Nm inet_ntoa | ||
| 316 | functions appeared in | ||
| 317 | .Bx 4.3 . | ||
| 318 | The | ||
| 319 | .Nm inet_pton | ||
| 320 | and | ||
| 321 | .Nm inet_ntop | ||
| 322 | functions appeared in BIND 4.9.4. | ||
| 181 | .Sh BUGS | 323 | .Sh BUGS |
| 182 | The value | 324 | The value |
| 183 | .Dv INADDR_NONE | 325 | .Dv INADDR_NONE |
| 184 | (0xffffffff) is a valid broadcast address, but | 326 | (0xffffffff) is a valid broadcast address, but |
| 185 | .Fn inet_addr | 327 | .Fn inet_addr |
| 186 | cannot return that value without indicating failure. | 328 | cannot return that value without indicating failure. |
| 329 | Also, | ||
| 330 | .Fn inet_addr | ||
| 331 | should have been designed to return a | ||
| 332 | .Li struct in_addr . | ||
| 187 | The newer | 333 | The newer |
| 188 | .Fn inet_aton | 334 | .Fn inet_aton |
| 189 | function does not share this problem. | 335 | function does not share these problems, and almost all existing code |
| 336 | should be modified to use | ||
| 337 | .Fn inet_aton | ||
| 338 | instead. | ||
| 339 | .Pp | ||
| 190 | The problem of host byte ordering versus network byte ordering is | 340 | The problem of host byte ordering versus network byte ordering is |
| 191 | confusing. | 341 | confusing. |
| 342 | .Pp | ||
| 192 | The string returned by | 343 | The string returned by |
| 193 | .Fn inet_ntoa | 344 | .Fn inet_ntoa |
| 194 | resides in a static memory area. | 345 | resides in a static memory area. |
| 195 | .Pp | ||
| 196 | Inet_addr should return a | ||
| 197 | .Fa struct in_addr . | ||
