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