1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified 1993-05-22, David Metcalfe
28 .\" Modified 1993-07-25, Rik Faith (faith@cs.unc.edu)
29 .\" Modified 1997-02-16, Andries Brouwer (aeb@cwi.nl)
30 .\" Modified 1998-12-21, Andries Brouwer (aeb@cwi.nl)
31 .\" Modified 2000-08-12, Andries Brouwer (aeb@cwi.nl)
32 .\" Modified 2001-05-19, Andries Brouwer (aeb@cwi.nl)
33 .\" Modified 2002-08-05, Michael Kerrisk
34 .\" Modified 2004-10-31, Andries Brouwer
36 .TH GETHOSTBYNAME 3 2007-10-16 "" "Linux Programmer's Manual"
38 gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
41 gethostbyname2, gethostbyname2_r, gethostbyname_r,
42 gethostent_r \- get network host entry
46 .B extern int h_errno;
48 .BI "struct hostent *gethostbyname(const char *" name );
50 .BR "#include <sys/socket.h>" " /* for AF_INET */"
51 .BI "struct hostent *gethostbyaddr(const void *" addr ,
52 .BI " socklen_t " len ", int " type );
54 .BI "void sethostent(int " stayopen );
56 .B void endhostent(void);
58 .BI "void herror(const char *" s );
60 .BI "const char *hstrerror(int " err );
62 /* System V/POSIX extension */
64 .B struct hostent *gethostent(void);
68 .BI "struct hostent *gethostbyname2(const char *" name ", int " af );
70 .B "int gethostent_r("
71 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
72 .BI " struct hostent **" result ", int *" h_errnop );
74 .BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type ,
75 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
76 .BI " struct hostent **" result ", int *" h_errnop );
78 .BI "int gethostbyname_r(const char *" name ,
79 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
80 .BI " struct hostent **" result ", int *" h_errnop );
82 .BI "int gethostbyname2_r(const char *" name ", int " af,
83 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
84 .BI " struct hostent **" result ", int *" h_errnop );
88 Feature Test Macro Requirements for glibc (see
89 .BR feature_test_macros (7)):
93 .BR gethostbyname2 (),
95 .BR gethostbyaddr_r (),
96 .BR gethostbyname_r (),
97 .BR gethostbyname2_r ():
98 _BSD_SOURCE || _SVID_SOURCE
101 These functions are obsolete.
102 Applications should use
110 function returns a structure of type
116 is either a host name, or an IPv4 address in standard dot notation,
117 or an IPv6 address in colon (and possibly dot) notation.
118 (See RFC\ 1884 for the description of IPv6 addresses.)
121 is an IPv4 or IPv6 address, no lookup is performed and
131 field of the returned
136 doesn't end in a dot and the environment variable
138 is set, the alias file pointed to by
140 will first be searched for
144 for the file format).
145 The current domain and its parents are searched unless \fIname\fP
150 function returns a structure of type \fIhostent\fP
151 for the given host address \fIaddr\fP of length \fIlen\fP and address type
153 Valid address types are
157 The host address argument is a pointer to a struct of a type depending
158 on the address type, for example a \fIstruct in_addr *\fP (probably
159 obtained via a call to
166 function specifies, if \fIstayopen\fP is true (1),
167 that a connected TCP socket should be used for the name server queries and
168 that the connection should remain open during successive queries.
169 Otherwise, name server queries will use UDP datagrams.
173 function ends the use of a TCP connection for name
178 function prints the error message associated
179 with the current value of \fIh_errno\fP on \fIstderr\fP.
183 function takes an error number
184 (typically \fIh_errno\fP) and returns the corresponding message string.
186 The domain name queries carried out by
190 use a combination of any or all of the name server
192 a broken out line from \fI/etc/hosts\fP, and the Network
193 Information Service (NIS or YP), depending upon the contents of the
197 .\" .BR resolv+ (8)).
198 The default action is to query
203 The \fIhostent\fP structure is defined in \fI<netdb.h>\fP as follows:
209 char *h_name; /* official name of host */
210 char **h_aliases; /* alias list */
211 int h_addrtype; /* host address type */
212 int h_length; /* length of address */
213 char **h_addr_list; /* list of addresses */
215 #define h_addr h_addr_list[0] /* for backward compatibility */
219 The members of the \fIhostent\fP structure are:
222 The official name of the host.
225 An array of alternative names for the host, terminated by a NULL pointer.
228 The type of address; always
235 The length of the address in bytes.
238 An array of pointers to network addresses for the host (in network byte
239 order), terminated by a NULL pointer.
242 The first address in \fIh_addr_list\fP for backward compatibility.
250 structure or a NULL pointer if an error occurs.
253 variable holds an error number.
254 When non-NULL, the return value may point at static data, see the notes below.
256 The variable \fIh_errno\fP can have the following values:
259 The specified host is unknown.
261 .BR NO_ADDRESS " or " NO_DATA
262 The requested name is valid but does not have an IP address.
265 A non-recoverable name server error occurred.
268 A temporary error occurred on an authoritative name server.
273 resolver configuration file
278 .I /etc/nsswitch.conf
279 name service switch configuration
281 4.3BSD, POSIX.1-2001.
287 may return pointers to static data, which may be overwritten by
291 does not suffice, since it contains pointers; a deep copy is required.
293 In the original BSD implementation the
300 The SUSv2 standard is buggy and declares the
306 (That is wrong, because it has to be
311 POSIX.1-2001 makes it
317 The BSD prototype for
321 for the first argument.
331 .BR gai_strerror (3).
332 .SS "System V/POSIX Extension"
335 call, that should return the next entry in the host data base.
336 When using DNS/BIND this does not make much sense, but it may
337 be reasonable if the host data base is a file that can be read
339 On many systems a routine of this name reads
342 .\" e.g., Linux, FreeBSD, Unixware, HP-UX
343 It may be available only when the library was built without DNS support.
344 .\" e.g., FreeBSD, AIX
345 The glibc version will ignore ipv6 entries.
346 This function is not reentrant,
347 and glibc adds a reentrant version
351 .BR gethostbyname2 ()
353 .BR gethostbyname (),
354 but permits to specify the address family to which the address must belong.
356 Glibc2 also has reentrant versions
358 .BR gethostbyaddr_r (),
359 .BR gethostbyname_r ()
361 .BR gethostbyname2_r ().
362 The caller supplies a
366 which will be filled in on success, and a temporary work buffer
372 will point to the result on success. In case of an error
373 or if no entry is found
376 The functions return 0 on success and a non-zero error number on failure.
377 In addition to the errors returned by the non-reentrant
378 versions of these functions, if
380 is too small, the functions will return
382 and the call should be retried with a larger buffer.
385 is not modified, but the address of a variable in which to store error numbers
390 .\" .BR getipnodebyaddr (3),
391 .\" .BR getipnodebyname (3),
397 .BR nsswitch.conf (5),