diff options
Diffstat (limited to 'src/lib/libc/net/gethostbyname.3')
| -rw-r--r-- | src/lib/libc/net/gethostbyname.3 | 297 |
1 files changed, 297 insertions, 0 deletions
diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 new file mode 100644 index 0000000000..1a627f403b --- /dev/null +++ b/src/lib/libc/net/gethostbyname.3 | |||
| @@ -0,0 +1,297 @@ | |||
| 1 | .\" $OpenBSD: gethostbyname.3,v 1.20 2003/06/30 16:54:53 millert Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 1983, 1987, 1991, 1993 | ||
| 4 | .\" The Regents of the University of California. All rights reserved. | ||
| 5 | .\" | ||
| 6 | .\" Redistribution and use in source and binary forms, with or without | ||
| 7 | .\" modification, are permitted provided that the following conditions | ||
| 8 | .\" are met: | ||
| 9 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 10 | .\" notice, this list of conditions and the following disclaimer. | ||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 13 | .\" documentation and/or other materials provided with the distribution. | ||
| 14 | .\" 3. Neither the name of the University nor the names of its contributors | ||
| 15 | .\" may be used to endorse or promote products derived from this software | ||
| 16 | .\" without specific prior written permission. | ||
| 17 | .\" | ||
| 18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 28 | .\" SUCH DAMAGE. | ||
| 29 | .\" | ||
| 30 | .Dd March 13, 1997 | ||
| 31 | .Dt GETHOSTBYNAME 3 | ||
| 32 | .Os | ||
| 33 | .Sh NAME | ||
| 34 | .Nm gethostbyname , | ||
| 35 | .Nm gethostbyname2 , | ||
| 36 | .Nm gethostbyaddr , | ||
| 37 | .Nm gethostent , | ||
| 38 | .Nm sethostent , | ||
| 39 | .Nm endhostent , | ||
| 40 | .Nm hstrerror , | ||
| 41 | .Nm herror | ||
| 42 | .Nd get network host entry | ||
| 43 | .Sh SYNOPSIS | ||
| 44 | .Fd #include <netdb.h> | ||
| 45 | .Fd extern int h_errno; | ||
| 46 | .Ft struct hostent * | ||
| 47 | .Fn gethostbyname "const char *name" | ||
| 48 | .Ft struct hostent * | ||
| 49 | .Fn gethostbyname2 "const char *name" "int af" | ||
| 50 | .Ft struct hostent * | ||
| 51 | .Fn gethostbyaddr "const char *addr" "int len" "int af" | ||
| 52 | .Ft struct hostent * | ||
| 53 | .Fn gethostent void | ||
| 54 | .Ft void | ||
| 55 | .Fn sethostent "int stayopen" | ||
| 56 | .Ft void | ||
| 57 | .Fn endhostent void | ||
| 58 | .Ft void | ||
| 59 | .Fn herror "const char *string" | ||
| 60 | .Ft const char * | ||
| 61 | .Fn hstrerror "int err" | ||
| 62 | .Sh DESCRIPTION | ||
| 63 | The | ||
| 64 | .Fn gethostbyname , | ||
| 65 | .Fn gethostbyname2 | ||
| 66 | and | ||
| 67 | .Fn gethostbyaddr | ||
| 68 | functions each return a pointer to an object with the following structure | ||
| 69 | describing an internet host referenced by name or by address, respectively. | ||
| 70 | This structure contains either information obtained from the name server (i.e., | ||
| 71 | .Xr resolver 3 | ||
| 72 | and | ||
| 73 | .Xr named 8 ) , | ||
| 74 | broken-out fields from a line in | ||
| 75 | .Pa /etc/hosts , | ||
| 76 | or database entries supplied by the | ||
| 77 | .Xr yp 8 | ||
| 78 | system. | ||
| 79 | .Xr resolv.conf 5 | ||
| 80 | describes how the particular database is chosen. | ||
| 81 | .Bd -literal | ||
| 82 | struct hostent { | ||
| 83 | char *h_name; /* official name of host */ | ||
| 84 | char **h_aliases; /* alias list */ | ||
| 85 | int h_addrtype; /* host address type */ | ||
| 86 | int h_length; /* length of address */ | ||
| 87 | char **h_addr_list; /* list of addresses from name server */ | ||
| 88 | }; | ||
| 89 | #define h_addr h_addr_list[0] /* address, for backward compatibility */ | ||
| 90 | .Ed | ||
| 91 | .Pp | ||
| 92 | The members of this structure are: | ||
| 93 | .Bl -tag -width h_addr_list | ||
| 94 | .It Fa h_name | ||
| 95 | Official name of the host. | ||
| 96 | .It Fa h_aliases | ||
| 97 | A NULL-terminated array of alternate names for the host. | ||
| 98 | .It Fa h_addrtype | ||
| 99 | The type of address being returned. | ||
| 100 | .It Fa h_length | ||
| 101 | The length, in bytes, of the address. | ||
| 102 | .It Fa h_addr_list | ||
| 103 | A zero-terminated array of network addresses for the host. | ||
| 104 | Host addresses are returned in network byte order. | ||
| 105 | .It Fa h_addr | ||
| 106 | The first address in | ||
| 107 | .Fa h_addr_list ; | ||
| 108 | this is for backward compatibility. | ||
| 109 | .El | ||
| 110 | .Pp | ||
| 111 | The function | ||
| 112 | .Fn gethostbyname | ||
| 113 | will search for the named host in the current domain and its parents | ||
| 114 | using the search lookup semantics detailed in | ||
| 115 | .Xr resolv.conf 5 | ||
| 116 | and | ||
| 117 | .Xr hostname 7 . | ||
| 118 | .Pp | ||
| 119 | .Fn gethostbyname2 | ||
| 120 | is an advanced form of | ||
| 121 | .Fn gethostbyname | ||
| 122 | which allows lookups in address families other than | ||
| 123 | .Dv AF_INET . | ||
| 124 | Currently, the only supported address family besides | ||
| 125 | .Dv AF_INET | ||
| 126 | is | ||
| 127 | .Dv AF_INET6 . | ||
| 128 | .Pp | ||
| 129 | The | ||
| 130 | .Fn gethostbyaddr | ||
| 131 | function will search for the specified address of length | ||
| 132 | .Fa len | ||
| 133 | in the address family | ||
| 134 | .Fa af . | ||
| 135 | The only address family currently supported is | ||
| 136 | .Dv AF_INET . | ||
| 137 | .Pp | ||
| 138 | The | ||
| 139 | .Fn sethostent | ||
| 140 | function may be used to request the use of a connected | ||
| 141 | .Tn TCP | ||
| 142 | socket for queries. | ||
| 143 | If the | ||
| 144 | .Fa stayopen | ||
| 145 | flag is non-zero, | ||
| 146 | this sets the option to send all queries to the name server using | ||
| 147 | .Tn TCP | ||
| 148 | and to retain the connection after each call to | ||
| 149 | .Fn gethostbyname | ||
| 150 | or | ||
| 151 | .Fn gethostbyaddr . | ||
| 152 | Otherwise, queries are performed using | ||
| 153 | .Tn UDP | ||
| 154 | datagrams. | ||
| 155 | .Pp | ||
| 156 | The | ||
| 157 | .Fn endhostent | ||
| 158 | function closes the | ||
| 159 | .Tn TCP | ||
| 160 | connection. | ||
| 161 | .Pp | ||
| 162 | The | ||
| 163 | .Fn herror | ||
| 164 | function prints an error message describing the failure. | ||
| 165 | If its argument | ||
| 166 | .Fa string | ||
| 167 | is non-null, | ||
| 168 | it is prepended to the message string and separated from it by a colon | ||
| 169 | .Pq Ql \&: | ||
| 170 | and a space. | ||
| 171 | The error message is printed with a trailing newline. | ||
| 172 | The contents of the error message is the same as that returned by | ||
| 173 | .Fn hstrerror | ||
| 174 | with argument | ||
| 175 | .Fa h_errno . | ||
| 176 | .Sh ENVIRONMENT | ||
| 177 | .Bl -tag -width HOSTALIASES | ||
| 178 | .It HOSTALIASES | ||
| 179 | A file containing local host aliases. | ||
| 180 | See | ||
| 181 | .Xr hostname 7 | ||
| 182 | for more information. | ||
| 183 | .It RES_OPTIONS | ||
| 184 | A list of options to override the resolver's internal defaults. | ||
| 185 | See | ||
| 186 | .Xr resolver 3 | ||
| 187 | for more information. | ||
| 188 | .El | ||
| 189 | .Sh FILES | ||
| 190 | .Bl -tag -width /etc/resolv.conf -compact | ||
| 191 | .It Pa /etc/hosts | ||
| 192 | .It Pa /etc/resolv.conf | ||
| 193 | .El | ||
| 194 | .Sh DIAGNOSTICS | ||
| 195 | Error return status from | ||
| 196 | .Fn gethostbyname , | ||
| 197 | .Fn gethostbyname2 , | ||
| 198 | and | ||
| 199 | .Fn gethostbyaddr | ||
| 200 | is indicated by return of a null pointer. | ||
| 201 | The external integer | ||
| 202 | .Va h_errno | ||
| 203 | may then be checked to see whether this is a temporary failure | ||
| 204 | or an invalid or unknown host. | ||
| 205 | .Pp | ||
| 206 | The variable | ||
| 207 | .Va h_errno | ||
| 208 | can have the following values: | ||
| 209 | .Bl -tag -width HOST_NOT_FOUND | ||
| 210 | .It Dv HOST_NOT_FOUND | ||
| 211 | No such host is known. | ||
| 212 | .It Dv TRY_AGAIN | ||
| 213 | This is usually a temporary error | ||
| 214 | and means that the local server did not receive | ||
| 215 | a response from an authoritative server. | ||
| 216 | A retry at some later time may succeed. | ||
| 217 | .It Dv NO_RECOVERY | ||
| 218 | Some unexpected server failure was encountered. | ||
| 219 | This is a non-recoverable error. | ||
| 220 | .It Dv NO_DATA | ||
| 221 | The requested name is valid but does not have an IP address; | ||
| 222 | this is not a temporary error. | ||
| 223 | This means that the name is known to the name server but there is no address | ||
| 224 | associated with this name. | ||
| 225 | Another type of request to the name server using this domain name | ||
| 226 | will result in an answer; | ||
| 227 | for example, a mail-forwarder may be registered for this domain. | ||
| 228 | .It Dv NETDB_INTERNAL | ||
| 229 | An internal error occurred. | ||
| 230 | This may occurs when an address family other than | ||
| 231 | .It Dv AF_INET | ||
| 232 | or | ||
| 233 | .It Dv AF_INET6 | ||
| 234 | is specified or when a resource is unable to be allocated. | ||
| 235 | the | ||
| 236 | .It Dv NETDB_SUCCESS | ||
| 237 | The function completed successfully. | ||
| 238 | .El | ||
| 239 | .Sh SEE ALSO | ||
| 240 | .Xr getaddrinfo 3 , | ||
| 241 | .Xr getnameinfo 3 , | ||
| 242 | .Xr resolver 3 , | ||
| 243 | .Xr hosts 5 , | ||
| 244 | .Xr resolv.conf 5 , | ||
| 245 | .Xr hostname 7 , | ||
| 246 | .Xr named 8 | ||
| 247 | .Sh HISTORY | ||
| 248 | The | ||
| 249 | .Fn herror | ||
| 250 | function appeared in | ||
| 251 | .Bx 4.3 . | ||
| 252 | The | ||
| 253 | .Fn endhostent , | ||
| 254 | .Fn gethostbyaddr , | ||
| 255 | .Fn gethostbyname , | ||
| 256 | .Fn gethostent , | ||
| 257 | and | ||
| 258 | .Fn sethostent | ||
| 259 | functions appeared in | ||
| 260 | .Bx 4.2 . | ||
| 261 | .Sh CAVEATS | ||
| 262 | If the search routines in | ||
| 263 | .Xr resolv.conf 5 | ||
| 264 | decide to read the | ||
| 265 | .Pa /etc/hosts | ||
| 266 | file, | ||
| 267 | .Fn gethostent | ||
| 268 | and other functions will | ||
| 269 | read the next line of the file, | ||
| 270 | re-opening the file if necessary. | ||
| 271 | .Pp | ||
| 272 | The | ||
| 273 | .Fn sethostent | ||
| 274 | function opens and/or rewinds the file | ||
| 275 | .Pa /etc/hosts . | ||
| 276 | If the | ||
| 277 | .Fa stayopen | ||
| 278 | argument is non-zero, the file will not be closed after each call to | ||
| 279 | .Fn gethostbyname , | ||
| 280 | .Fn gethostbyname2 , | ||
| 281 | or | ||
| 282 | .Fn gethostbyaddr . | ||
| 283 | .Pp | ||
| 284 | The | ||
| 285 | .Fn endhostent | ||
| 286 | function closes the file. | ||
| 287 | .Sh BUGS | ||
| 288 | These functions use static data storage; | ||
| 289 | if the data is needed for future use, it should be | ||
| 290 | copied before any subsequent calls overwrite it. | ||
| 291 | Only the Internet | ||
| 292 | address formats are currently understood. | ||
| 293 | .Pp | ||
| 294 | YP does not support any address families other than | ||
| 295 | .Dv AF_INET | ||
| 296 | and uses | ||
| 297 | the traditional database format. | ||
