3 .\" Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
5 .\" Permission to use, copy, modify, and/or distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 .\" PERFORMANCE OF THIS SOFTWARE.
17 .\" Id: gethostbyname.3,v 1.3 2009/01/22 23:49:23 tbox Exp
20 .Dt GETHOSTBYNAME @LIB_NETWORK_EXT_U@
29 .Nd get network host entry
31 .Fd #include <netdb.h>
36 .Fn gethostbyname "char *name"
38 .Fn gethostbyname2 "char *name" "int af"
40 .Fn gethostbyaddr "char *addr" "int len, type"
43 .Fn sethostent "int stayopen"
45 .Fn herror "char *string"
51 each return a pointer to a
53 structure (see below) describing an internet host
54 referenced by name or by address, as the function names indicate.
55 This structure contains either the information obtained from the name server,
56 or broken-out fields from a line in
58 If the local name server is not running, these routines do a lookup in
60 .Bd -literal -offset indent
62 char *h_name; /* official name of host */
63 char **h_aliases; /* alias list */
64 int h_addrtype; /* host address type */
65 int h_length; /* length of address */
66 char **h_addr_list; /* list of addresses from name server */
69 #define h_addr h_addr_list[0] /* address, for backward compatibility */
72 The members of this structure are:
73 .Bl -tag -width "h_addr_list"
75 Official name of the host.
77 A zero-terminated array of alternate names for the host.
79 The type of address being returned; usually
82 The length, in bytes, of the address.
84 A zero-terminated array of network addresses for the host.
85 Host addresses are returned in network byte order.
89 this is for backward compatibility.
92 When using the nameserver,
94 will search for the named host in each parent domain given in the
97 .Xr resolv.conf @FORMAT_EXT@
98 unless the name contains a dot
100 If the name contains no dot, and if the environment variable
102 contains the name of an alias file, the alias file will first be searched
103 for an alias matching the input name.
105 .Xr hostname @DESC_EXT@
106 for the domain search procedure and the alias file format.
111 intended to allow lookups in address families other than
117 argument must be specified as
119 else the function will return
127 may be used to request the use of a connected TCP socket for queries.
131 this sets the option to send all queries to the name server using TCP
132 and to retain the connection after each call to
136 Otherwise, queries are performed using UDP datagrams.
139 closes the TCP connection.
141 .Bl -tag -width "HOSTALIASES " -compact
143 Name of file containing
144 .Pq Ar host alias , full hostname
148 .Bl -tag -width "HOSTALIASES " -compact
151 .Xr hosts @FORMAT_EXT@ .
155 Error return status from
159 is indicated by return of a null pointer.
162 may then be checked to see whether this is a temporary failure
163 or an invalid or unknown host.
166 can be used to print an error message describing the failure.
169 is non-NULL, it is printed, followed by a colon and a space.
170 The error message is printed with a trailing newline.
173 can have the following values:
174 .Bl -tag -width "HOST_NOT_FOUND " -offset indent
175 .It Dv NETDB_INTERNAL
176 This indicates an internal error in the library, unrelated to the network
179 will be valid in this case; see
180 .Xr perror @SYSCALL_EXT@ .
181 .It Dv HOST_NOT_FOUND
182 No such host is known.
184 This is usually a temporary error
185 and means that the local server did not receive
186 a response from an authoritative server.
187 A retry at some later time may succeed.
189 Some unexpected server failure was encountered.
190 This is a non-recoverable error, as one might expect.
192 The requested name is valid but does not have an IP address;
193 this is not a temporary error.
194 This means that the name is known to the name server but there is no address
195 associated with this name.
196 Another type of request to the name server using this domain name
197 will result in an answer;
198 for example, a mail-forwarder may be registered for this domain.
201 .Xr hosts @FORMAT_EXT@ ,
202 .Xr hostname @DESC_EXT@ ,
203 .Xr resolver @LIB_NETWORK_EXT@ ,
204 .Xr resolver @FORMAT_EXT@ .
215 is built to use only the routines to lookup in
217 and not the name server:
218 .Bd -ragged -offset indent
221 reads the next line of
223 opening the file if necessary.
226 is redefined to open and rewind the file. If the
228 argument is non-zero,
229 the hosts data base will not be closed after each call to
235 is redefined to close the file.
238 All information is contained in a static area so it must be copied if it is
239 to be saved. Only the Internet address format is currently understood.