diff options
Diffstat (limited to 'src/lib/libc/net/inet_addr.3')
| -rw-r--r-- | src/lib/libc/net/inet_addr.3 | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet_addr.3 b/src/lib/libc/net/inet_addr.3 new file mode 100644 index 0000000000..abe9e5d8c9 --- /dev/null +++ b/src/lib/libc/net/inet_addr.3 | |||
| @@ -0,0 +1,197 @@ | |||
| 1 | .\" $OpenBSD: inet_addr.3,v 1.1 2014/04/19 11:18:01 guenther 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. Neither the name of the University nor the names of its contributors | ||
| 16 | .\" may be used to endorse or promote products derived from this software | ||
| 17 | .\" without specific prior written permission. | ||
| 18 | .\" | ||
| 19 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | .\" SUCH DAMAGE. | ||
| 30 | .\" | ||
| 31 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 | ||
| 32 | .\" | ||
| 33 | .Dd $Mdocdate: April 19 2014 $ | ||
| 34 | .Dt INET_ADDR 3 | ||
| 35 | .Os | ||
| 36 | .Sh NAME | ||
| 37 | .Nm inet_aton , | ||
| 38 | .Nm inet_addr , | ||
| 39 | .Nm inet_network , | ||
| 40 | .Nm inet_ntoa | ||
| 41 | .Nd Internet Protocol version 4 (IPv4) address manipulation routines | ||
| 42 | .Sh SYNOPSIS | ||
| 43 | .In arpa/inet.h | ||
| 44 | .Ft int | ||
| 45 | .Fn inet_aton "const char *cp" "struct in_addr *addr" | ||
| 46 | .Ft in_addr_t | ||
| 47 | .Fn inet_addr "const char *cp" | ||
| 48 | .Ft in_addr_t | ||
| 49 | .Fn inet_network "const char *cp" | ||
| 50 | .Ft char * | ||
| 51 | .Fn inet_ntoa "struct in_addr in" | ||
| 52 | .Sh DESCRIPTION | ||
| 53 | The functions presented here only support IPv4 addresses. | ||
| 54 | In order to support IPv6 addresses as well, | ||
| 55 | .Xr inet_ntop 3 | ||
| 56 | and | ||
| 57 | .Xr inet_pton 3 | ||
| 58 | should be used rather than the functions presented here. | ||
| 59 | Scoped IPv6 addresses are supported via | ||
| 60 | .Xr getaddrinfo 3 | ||
| 61 | and | ||
| 62 | .Xr getnameinfo 3 . | ||
| 63 | .Pp | ||
| 64 | The routines | ||
| 65 | .Fn inet_aton , | ||
| 66 | .Fn inet_addr , | ||
| 67 | and | ||
| 68 | .Fn inet_network | ||
| 69 | interpret character strings representing | ||
| 70 | numbers expressed in the Internet standard | ||
| 71 | .Dq dot | ||
| 72 | notation. | ||
| 73 | .Pp | ||
| 74 | The | ||
| 75 | .Fn inet_aton | ||
| 76 | routine interprets the specified character string as an Internet address, | ||
| 77 | placing the address into the structure provided. | ||
| 78 | It returns 1 if the string was successfully interpreted, | ||
| 79 | or 0 if the string was invalid. | ||
| 80 | .Pp | ||
| 81 | The | ||
| 82 | .Fn inet_addr | ||
| 83 | and | ||
| 84 | .Fn inet_network | ||
| 85 | functions return numbers suitable for use | ||
| 86 | as Internet addresses and Internet network | ||
| 87 | numbers, respectively. | ||
| 88 | Both functions return the constant | ||
| 89 | .Dv INADDR_NONE | ||
| 90 | if the specified character string is malformed. | ||
| 91 | .Pp | ||
| 92 | The routine | ||
| 93 | .Fn inet_ntoa | ||
| 94 | takes an Internet address and returns an | ||
| 95 | ASCII string representing the address in dot notation. | ||
| 96 | .Pp | ||
| 97 | All Internet addresses are returned in network | ||
| 98 | order (bytes ordered from left to right). | ||
| 99 | All network numbers and local address parts are | ||
| 100 | returned as machine format integer values. | ||
| 101 | .Sh INTERNET ADDRESSES (IP VERSION 4) | ||
| 102 | Values specified using dot notation take one of the following forms: | ||
| 103 | .Bd -literal -offset indent | ||
| 104 | a.b.c.d | ||
| 105 | a.b.c | ||
| 106 | a.b | ||
| 107 | a | ||
| 108 | .Ed | ||
| 109 | .Pp | ||
| 110 | When four parts are specified, each is interpreted | ||
| 111 | as a byte of data and assigned, from left to right, | ||
| 112 | to the four bytes of an Internet address. | ||
| 113 | Note that when an Internet address is viewed as a 32-bit | ||
| 114 | integer quantity on a system that uses little-endian | ||
| 115 | byte order | ||
| 116 | (such as the Intel 386, 486 and Pentium processors) | ||
| 117 | the bytes referred to above appear as | ||
| 118 | .Dq Li d.c.b.a . | ||
| 119 | That is, little-endian bytes are ordered from right to left. | ||
| 120 | .Pp | ||
| 121 | When a three part address is specified, the last | ||
| 122 | part is interpreted as a 16-bit quantity and placed | ||
| 123 | in the rightmost two bytes of the network address. | ||
| 124 | This makes the three part address format convenient | ||
| 125 | for specifying Class B network addresses as | ||
| 126 | .Dq Li 128.net.host . | ||
| 127 | .Pp | ||
| 128 | When a two part address is supplied, the last part | ||
| 129 | is interpreted as a 24-bit quantity and placed in | ||
| 130 | the rightmost three bytes of the network address. | ||
| 131 | This makes the two part address format convenient | ||
| 132 | for specifying Class A network addresses as | ||
| 133 | .Dq Li net.host . | ||
| 134 | .Pp | ||
| 135 | When only one part is given, the value is stored | ||
| 136 | directly in the network address without any byte | ||
| 137 | rearrangement. | ||
| 138 | .Pp | ||
| 139 | All numbers supplied as | ||
| 140 | .Dq parts | ||
| 141 | in a dot notation | ||
| 142 | may be decimal, octal, or hexadecimal, as specified | ||
| 143 | in the C language (i.e., a leading 0x or 0X implies | ||
| 144 | hexadecimal; a leading 0 implies octal; | ||
| 145 | otherwise, the number is interpreted as decimal). | ||
| 146 | .Sh SEE ALSO | ||
| 147 | .Xr byteorder 3 , | ||
| 148 | .Xr gethostbyname 3 , | ||
| 149 | .Xr getnetent 3 , | ||
| 150 | .Xr inet_lnaof 3 , | ||
| 151 | .Xr inet_net 3 , | ||
| 152 | .Xr inet_ntop 3 , | ||
| 153 | .Xr hosts 5 , | ||
| 154 | .Xr networks 5 | ||
| 155 | .Sh STANDARDS | ||
| 156 | The | ||
| 157 | .Nm inet_addr | ||
| 158 | and | ||
| 159 | .Nm inet_aton | ||
| 160 | functions conform to | ||
| 161 | .St -p1003.1-2008 . | ||
| 162 | .Sh HISTORY | ||
| 163 | The | ||
| 164 | .Nm inet_addr | ||
| 165 | and | ||
| 166 | .Nm inet_network | ||
| 167 | functions appeared in | ||
| 168 | .Bx 4.2 . | ||
| 169 | The | ||
| 170 | .Nm inet_aton | ||
| 171 | and | ||
| 172 | .Nm inet_ntoa | ||
| 173 | functions appeared in | ||
| 174 | .Bx 4.3 . | ||
| 175 | .Sh BUGS | ||
| 176 | The value | ||
| 177 | .Dv INADDR_NONE | ||
| 178 | (0xffffffff) is a valid broadcast address, but | ||
| 179 | .Fn inet_addr | ||
| 180 | cannot return that value without indicating failure. | ||
| 181 | Also, | ||
| 182 | .Fn inet_addr | ||
| 183 | should have been designed to return a | ||
| 184 | .Li struct in_addr . | ||
| 185 | The newer | ||
| 186 | .Fn inet_aton | ||
| 187 | function does not share these problems, and almost all existing code | ||
| 188 | should be modified to use | ||
| 189 | .Fn inet_aton | ||
| 190 | instead. | ||
| 191 | .Pp | ||
| 192 | The problem of host byte ordering versus network byte ordering is | ||
| 193 | confusing. | ||
| 194 | .Pp | ||
| 195 | The string returned by | ||
| 196 | .Fn inet_ntoa | ||
| 197 | resides in a static memory area. | ||
