1 .\" $OpenBSD: gethostbyname.3,v 1.16 2000/12/24 00:30:56 aaron 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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 .Nd get network host entry
48 .Fd #include <netdb.h>
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" "int len" "int af"
59 .Fn sethostent "int stayopen"
63 .Fn herror "const char *string"
65 .Fn hstrerror "int err"
71 functions each return a pointer to an object with the following structure
72 describing an internet host referenced by name or by address, respectively.
73 This structure contains either information obtained from the name server (i.e.,
77 broken-out fields from a line in
79 or database entries supplied by the
83 describes how the particular database is chosen.
86 char *h_name; /* official name of host */
87 char **h_aliases; /* alias list */
88 int h_addrtype; /* host address type */
89 int h_length; /* length of address */
90 char **h_addr_list; /* list of addresses from name server */
92 #define h_addr h_addr_list[0] /* address, for backward compatibility */
95 The members of this structure are:
96 .Bl -tag -width h_addr_list
98 Official name of the host.
100 A zero-terminated array of alternate names for the host.
102 The type of address being returned.
104 The length, in bytes, of the address.
106 A zero-terminated array of network addresses for the host.
107 Host addresses are returned in network byte order.
111 this is for backward compatibility.
116 will search for the named host in the current domain and its parents
117 using the search lookup semantics detailed in
123 is an advanced form of
125 which allows lookups in address families other than
132 function will search for the specified address of length
134 in the address family
136 The only address family currently supported is
141 function may be used to request the use of a connected
147 this sets the option to send all queries to the name server using
149 and to retain the connection after each call to
153 Otherwise, queries are performed using
165 function prints an error message describing the failure.
169 it is prepended to the message string and separated from it by a colon
172 The error message is printed with a trailing newline.
173 The contents of the error message is the same as that returned by
178 .Bl -tag -width /etc/resolv.conf -compact
180 .It Pa /etc/resolv.conf
183 Error return status from
188 is indicated by return of a null pointer.
191 may then be checked to see whether this is a temporary failure
192 or an invalid or unknown host.
196 can have the following values:
197 .Bl -tag -width HOST_NOT_FOUND
198 .It Dv HOST_NOT_FOUND
199 No such host is known.
201 This is usually a temporary error
202 and means that the local server did not receive
203 a response from an authoritative server.
204 A retry at some later time may succeed.
206 Some unexpected server failure was encountered.
207 This is a non-recoverable error.
209 The requested name is valid but does not have an IP address;
210 this is not a temporary error.
211 This means that the name is known to the name server but there is no address
212 associated with this name.
213 Another type of request to the name server using this domain name
214 will result in an answer;
215 for example, a mail-forwarder may be registered for this domain.
226 If the search routines in
232 and other functions will
233 read the next line of the file,
234 re-opening the file if necessary.
238 function opens and/or rewinds the file
242 argument is non-zero, the file will not be closed after each call to
250 function closes the file.
263 functions appeared in
266 These functions use static data storage;
267 if the data is needed for future use, it should be
268 copied before any subsequent calls overwrite it.
270 address formats are currently understood.
272 YP does not support any address families other than
275 the traditional database format.