diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libc/net/inet.3 | 184 |
1 files changed, 154 insertions, 30 deletions
diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3 index db28804e32..2fb86cd927 100644 --- a/src/lib/libc/net/inet.3 +++ b/src/lib/libc/net/inet.3 | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | .\" $OpenBSD: inet.3,v 1.3 1997/04/05 21:13:10 millert Exp $ | 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 $ | ||
| 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. |
| @@ -31,36 +32,44 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 33 | .\" SUCH DAMAGE. |
| 33 | .\" | 34 | .\" |
| 34 | .Dd June 4, 1993 | 35 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 |
| 36 | .\" | ||
| 37 | .Dd June 18, 1997 | ||
| 35 | .Dt INET 3 | 38 | .Dt INET 3 |
| 36 | .Os BSD 4.2 | 39 | .Os BSD 4.2 |
| 37 | .Sh NAME | 40 | .Sh NAME |
| 38 | .Nm inet_aton , | ||
| 39 | .Nm inet_addr , | 41 | .Nm inet_addr , |
| 42 | .Nm inet_aton , | ||
| 43 | .Nm inet_lnaof , | ||
| 44 | .Nm inet_makeaddr , | ||
| 45 | .Nm inet_netof , | ||
| 40 | .Nm inet_network , | 46 | .Nm inet_network , |
| 41 | .Nm inet_ntoa , | 47 | .Nm inet_ntoa , |
| 42 | .Nm inet_makeaddr , | 48 | .Nm inet_ntop , |
| 43 | .Nm inet_lnaof , | 49 | .Nm inet_pton |
| 44 | .Nm inet_netof | ||
| 45 | .Nd Internet address manipulation routines | 50 | .Nd Internet address manipulation routines |
| 46 | .Sh SYNOPSIS | 51 | .Sh SYNOPSIS |
| 47 | .Fd #include <sys/socket.h> | 52 | .Fd #include <sys/socket.h> |
| 48 | .Fd #include <netinet/in.h> | 53 | .Fd #include <netinet/in.h> |
| 49 | .Fd #include <arpa/inet.h> | 54 | .Fd #include <arpa/inet.h> |
| 50 | .Ft int | 55 | .Ft in_addr_t |
| 51 | .Fn inet_aton "const char *cp" "struct in_addr *pin" | ||
| 52 | .Ft in_addr_t | ||
| 53 | .Fn inet_addr "const char *cp" | 56 | .Fn inet_addr "const char *cp" |
| 54 | .Ft in_addr_t | 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 | ||
| 55 | .Fn inet_network "const char *cp" | 66 | .Fn inet_network "const char *cp" |
| 56 | .Ft char * | 67 | .Ft char * |
| 57 | .Fn inet_ntoa "struct in_addr in" | 68 | .Fn inet_ntoa "struct in_addr in" |
| 58 | .Ft struct in_addr | 69 | .Ft const char * |
| 59 | .Fn inet_makeaddr "int net" "int lna" | 70 | .Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size" |
| 60 | .Ft in_addr_t | 71 | .Ft int |
| 61 | .Fn inet_lnaof "struct in_addr in" | 72 | .Fn inet_pton "int af" "const char *src" "void *dst" |
| 62 | .Ft in_addr_t | ||
| 63 | .Fn inet_netof "struct in_addr in" | ||
| 64 | .Sh DESCRIPTION | 73 | .Sh DESCRIPTION |
| 65 | The routines | 74 | The routines |
| 66 | .Fn inet_aton , | 75 | .Fn inet_aton , |
| @@ -72,6 +81,17 @@ numbers expressed in the Internet standard | |||
| 72 | .Ql \&. | 81 | .Ql \&. |
| 73 | notation. | 82 | notation. |
| 74 | The | 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 | ||
| 75 | .Fn inet_aton | 95 | .Fn inet_aton |
| 76 | routine interprets the specified character string as an Internet address, | 96 | routine interprets the specified character string as an Internet address, |
| 77 | placing the address into the structure provided. | 97 | placing the address into the structure provided. |
| @@ -84,6 +104,16 @@ and | |||
| 84 | functions return numbers suitable for use | 104 | functions return numbers suitable for use |
| 85 | as Internet addresses and Internet network | 105 | as Internet addresses and Internet network |
| 86 | numbers, respectively. | 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. | ||
| 87 | The routine | 117 | The routine |
| 88 | .Fn inet_ntoa | 118 | .Fn inet_ntoa |
| 89 | takes an Internet address and returns an | 119 | takes an Internet address and returns an |
| @@ -106,7 +136,7 @@ All Internet addresses are returned in network | |||
| 106 | order (bytes ordered from left to right). | 136 | order (bytes ordered from left to right). |
| 107 | All network numbers and local address parts are | 137 | All network numbers and local address parts are |
| 108 | returned as machine format integer values. | 138 | returned as machine format integer values. |
| 109 | .Sh INTERNET ADDRESSES | 139 | .Sh INTERNET ADDRESSES (IP VERSION 4) |
| 110 | Values specified using the | 140 | Values specified using the |
| 111 | .Ql \&. | 141 | .Ql \&. |
| 112 | notation take one | 142 | notation take one |
| @@ -122,15 +152,14 @@ When four parts are specified, each is interpreted | |||
| 122 | as a byte of data and assigned, from left to right, | 152 | as a byte of data and assigned, from left to right, |
| 123 | to the four bytes of an Internet address. Note | 153 | to the four bytes of an Internet address. Note |
| 124 | that when an Internet address is viewed as a 32-bit | 154 | that when an Internet address is viewed as a 32-bit |
| 125 | integer quantity on the | 155 | integer quantity on a system that uses little-endian |
| 126 | .Tn VAX | 156 | byte order (such as the |
| 127 | the bytes referred to | 157 | .Tn Intel 386, 486 |
| 128 | above appear as | 158 | and |
| 159 | .Tn Pentium | ||
| 160 | processors) the bytes referred to above appear as | ||
| 129 | .Dq Li d.c.b.a . | 161 | .Dq Li d.c.b.a . |
| 130 | That is, | 162 | That is, little-endian bytes are ordered from right to left. |
| 131 | .Tn VAX | ||
| 132 | bytes are | ||
| 133 | ordered from right to left. | ||
| 134 | .Pp | 163 | .Pp |
| 135 | When a three part address is specified, the last | 164 | When a three part address is specified, the last |
| 136 | part is interpreted as a 16-bit quantity and placed | 165 | part is interpreted as a 16-bit quantity and placed |
| @@ -159,6 +188,68 @@ may be decimal, octal, or hexadecimal, as specified | |||
| 159 | in the C language (i.e., a leading 0x or 0X implies | 188 | in the C language (i.e., a leading 0x or 0X implies |
| 160 | hexadecimal; otherwise, a leading 0 implies octal; | 189 | hexadecimal; otherwise, a leading 0 implies octal; |
| 161 | otherwise, the number is interpreted as decimal). | 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 | ||
| 162 | .Sh DIAGNOSTICS | 253 | .Sh DIAGNOSTICS |
| 163 | The constant | 254 | The constant |
| 164 | .Dv INADDR_NONE | 255 | .Dv INADDR_NONE |
| @@ -168,14 +259,44 @@ and | |||
| 168 | .Fn inet_network | 259 | .Fn inet_network |
| 169 | for malformed requests. | 260 | for malformed requests. |
| 170 | .Sh SEE ALSO | 261 | .Sh SEE ALSO |
| 262 | .Xr byteorder 3 , | ||
| 171 | .Xr gethostbyname 3 , | 263 | .Xr gethostbyname 3 , |
| 172 | .Xr getnetent 3 , | 264 | .Xr getnetent 3 , |
| 265 | .Xr inet_net 3 , | ||
| 173 | .Xr hosts 5 , | 266 | .Xr hosts 5 , |
| 174 | .Xr networks 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 . | ||
| 175 | .Sh HISTORY | 279 | .Sh HISTORY |
| 176 | These | 280 | The |
| 177 | functions appeared in | 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 | ||
| 178 | .Bx 4.2 . | 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. | ||
| 179 | .Sh BUGS | 300 | .Sh BUGS |
| 180 | The value | 301 | The value |
| 181 | .Dv INADDR_NONE | 302 | .Dv INADDR_NONE |
| @@ -185,11 +306,14 @@ cannot return that value without indicating failure. | |||
| 185 | The newer | 306 | The newer |
| 186 | .Fn inet_aton | 307 | .Fn inet_aton |
| 187 | function does not share this problem. | 308 | function does not share this problem. |
| 309 | .Pp | ||
| 188 | The problem of host byte ordering versus network byte ordering is | 310 | The problem of host byte ordering versus network byte ordering is |
| 189 | confusing. | 311 | confusing. |
| 312 | .Pp | ||
| 190 | The string returned by | 313 | The string returned by |
| 191 | .Fn inet_ntoa | 314 | .Fn inet_ntoa |
| 192 | resides in a static memory area. | 315 | resides in a static memory area. |
| 193 | .Pp | 316 | .Pp |
| 194 | Inet_addr should return a | 317 | .Fn inet_addr |
| 195 | .Fa struct in_addr . | 318 | should return a |
| 319 | .Fa "struct in_addr" . | ||
