1 .\" $NetBSD: gethostbyname.3,v 1.27 2004/08/17 13:45:14 wiz Exp $
3 .\" Copyright (c) 1983, 1987, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
30 .\" @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
44 .Nd get network host entry
49 .Fd extern int h_errno;
51 .Fn gethostbyname "const char *name"
53 .Fn gethostbyname2 "const char *name" "int af"
55 .Fn gethostbyaddr "const char *addr" "socklen_t len" "int type"
59 .Fn sethostent "int stayopen"
63 .Fn herror "const char *string"
65 .Fn hstrerror "int err"
73 each return a pointer to an object with the
74 following structure describing an internet host.
77 char *h_name; /* official name of host */
78 char **h_aliases; /* alias list */
79 int h_addrtype; /* host address type */
80 int h_length; /* length of address */
81 char **h_addr_list; /* list of addresses from name server */
83 #define h_addr h_addr_list[0] /* address, for backward compatibility */
86 The members of this structure are:
87 .Bl -tag -width h_addr_list
89 Official name of the host.
91 A NULL-terminated array of alternative names for the host.
93 The type of address being returned; currently always
96 The length, in bytes, of the address.
98 A NULL-terminated array of network addresses for the host.
99 Host addresses are returned in network byte order.
103 this is for backward compatibility.
110 the host is specified by name,
111 or using a string representation of a numeric address.
114 the host is specified using a binary representation of an address.
118 structure may contain
119 the result of a simple string to binary conversion,
120 information obtained from the domain name resolver (see
122 broken-out fields from a line in
124 or database entries supplied by the
127 The order of the lookups is controlled by the
130 .Xr nsswitch.conf 5 .
132 When using the domain name resolver,
136 will search for the named host in the current domain and its parents
137 unless the name ends in a dot.
138 If the name contains no dot, and if the environment variable
140 contains the name of an alias file, the alias file will first be searched
141 for an alias matching the input name.
144 for the domain search procedure and the alias file format.
148 function is an evolution of
150 which is intended to allow lookups in address families other than
156 argument must be specified as
160 else the function will return
170 reads the next line of the
172 file, opening the file if necessary.
177 may be used to request the use of a connected
183 this sets the option to send all queries to the name server using
185 and to retain the connection after each call to
190 Otherwise, queries are performed using
203 function writes a message to the diagnostic output consisting of the
206 the constant string ": ", and a message corresponding to the value of
211 function returns a string which is the message text corresponding to the
216 .Bl -tag -width /etc/hosts -compact
220 Error return status from
226 is indicated by return of a null pointer.
229 may then be checked to see whether this is a temporary failure
230 or an invalid or unknown host.
233 can be used to print an error message describing the failure.
238 it is printed, followed by a colon and a space.
239 The error message is printed with a trailing newline.
243 can have the following values:
244 .Bl -tag -width HOST_NOT_FOUND
245 .It Dv HOST_NOT_FOUND
246 No such host is known.
248 This is usually a temporary error
249 and means that the local server did not receive
250 a response from an authoritative server.
251 A retry at some later time may succeed.
253 Some unexpected server failure was encountered.
254 This is a non-recoverable error.
256 The requested name is valid but does not have an IP address;
257 this is not a temporary error.
258 This means that the name is known to the name server but there is no address
259 associated with this name.
260 Another type of request to the name server using this domain name
261 will result in an answer;
262 for example, a mail-forwarder may be registered for this domain.
267 .Xr nsswitch.conf 5 ,
282 functions appeared in
286 function first appeared in bind-4.9.4.
287 IPv6 support was implemented in WIDE Hydrangea IPv6 protocol stack kit.
289 If the search routines specified in
299 read the next line of the file,
300 re-opening the file if necessary.
305 opens and/or rewinds the file
309 argument is non-zero,
310 the file will not be closed after each call to
319 function closes the file.
321 These functions use static data storage;
322 if the data is needed for future use, it should be
323 copied before any subsequent calls overwrite it.
325 address format is currently understood.
329 does not currently follow the search order specified in