1 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 .\" Copyright (c) 1983, 1987 The Regents of the University of California.
16 .\" All rights reserved.
18 .\" Redistribution and use in source and binary forms are permitted provided
19 .\" that: (1) source distributions retain this entire copyright notice and
20 .\" comment, and (2) distributions including binaries display the following
21 .\" acknowledgement: ``This product includes software developed by the
22 .\" University of California, Berkeley and its contributors'' in the
23 .\" documentation or other materials provided with the distribution and in
24 .\" all advertising materials mentioning features or use of this software.
25 .\" Neither the name of the University nor the names of its contributors may
26 .\" be used to endorse or promote products derived from this software without
27 .\" specific prior written permission.
28 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
29 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
30 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32 .\" @(#)gethostbyname.3 6.12 (Berkeley) 6/23/90
44 .Nd get network host entry
46 .Fd #include <netdb.h>
51 .Fn gethostbyname "char *name"
53 .Fn gethostbyname2 "char *name" "int af"
55 .Fn gethostbyaddr "char *addr" "int len, type"
58 .Fn sethostent "int stayopen"
60 .Fn herror "char *string"
66 each return a pointer to a
68 structure (see below) describing an internet host
69 referenced by name or by address, as the function names indicate.
70 This structure contains either the information obtained from the name server,
71 or broken-out fields from a line in
73 If the local name server is not running, these routines do a lookup in
75 .Bd -literal -offset indent
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 */
84 #define h_addr h_addr_list[0] /* address, for backward compatibility */
87 The members of this structure are:
88 .Bl -tag -width "h_addr_list"
90 Official name of the host.
92 A zero-terminated array of alternate names for the host.
94 The type of address being returned; usually
97 The length, in bytes, of the address.
99 A zero-terminated array of network addresses for the host.
100 Host addresses are returned in network byte order.
104 this is for backward compatibility.
107 When using the nameserver,
109 will search for the named host in each parent domain given in the
113 unless the name contains a dot
115 If the name contains no dot, and if the environment variable
117 contains the name of an alias file, the alias file will first be searched
118 for an alias matching the input name.
121 for the domain search procedure and the alias file format.
126 intended to allow lookups in address families other than
132 argument must be specified as
134 else the function will return
142 may be used to request the use of a connected TCP socket for queries.
146 this sets the option to send all queries to the name server using TCP
147 and to retain the connection after each call to
151 Otherwise, queries are performed using UDP datagrams.
154 closes the TCP connection.
156 .Bl -tag -width "HOSTALIASES " -compact
158 Name of file containing
159 .Pq Ar host alias , full hostname
163 .Bl -tag -width "HOSTALIASES " -compact
170 Error return status from
174 is indicated by return of a null pointer.
177 may then be checked to see whether this is a temporary failure
178 or an invalid or unknown host.
181 can be used to print an error message describing the failure.
184 is non-NULL, it is printed, followed by a colon and a space.
185 The error message is printed with a trailing newline.
188 can have the following values:
189 .Bl -tag -width "HOST_NOT_FOUND " -offset indent
190 .It Dv NETDB_INTERNAL
191 This indicates an internal error in the library, unrelated to the network
194 will be valid in this case; see
196 .It Dv HOST_NOT_FOUND
197 No such host is known.
199 This is usually a temporary error
200 and means that the local server did not receive
201 a response from an authoritative server.
202 A retry at some later time may succeed.
204 Some unexpected server failure was encountered.
205 This is a non-recoverable error, as one might expect.
207 The requested name is valid but does not have an IP address;
208 this is not a temporary error.
209 This means that the name is known to the name server but there is no address
210 associated with this name.
211 Another type of request to the name server using this domain name
212 will result in an answer;
213 for example, a mail-forwarder may be registered for this domain.
230 is built to use only the routines to lookup in
232 and not the name server:
233 .Bd -ragged -offset indent
236 reads the next line of
238 opening the file if necessary.
241 is redefined to open and rewind the file. If the
243 argument is non-zero,
244 the hosts data base will not be closed after each call to
250 is redefined to close the file.
253 All information is contained in a static area so it must be copied if it is
254 to be saved. Only the Internet address format is currently understood.