1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="TCP/IP Library Reference"
23 HREF="tcpip-library-reference.html"><LINK
26 HREF="net-common-tcpip-manpages-getaddrinfo.html"><LINK
29 HREF="net-common-tcpip-manpages-getifaddrs.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="net-common-tcpip-manpages-getaddrinfo.html"
65 >Chapter 38. TCP/IP Library Reference</TD
71 HREF="net-common-tcpip-manpages-getifaddrs.html"
85 NAME="NET-COMMON-TCPIP-MANPAGES-GETHOSTBYNAME">gethostbyname</H1
94 >GETHOSTBYNAME(3) System Library Functions Manual GETHOSTBYNAME(3)
97 gethostbyname, gethostbyname2, gethostbyaddr, gethostent, sethostent,
98 endhostent, hstrerror, herror - get network host entry
101 #include <netdb.h>
105 gethostbyname(const char *name);
108 gethostbyname2(const char *name, int af);
111 gethostbyaddr(const char *addr, int len, int af);
117 sethostent(int stayopen);
123 herror(const char *string);
129 The gethostbyname() and gethostbyaddr() functions each return a pointer
130 to an object with the following structure describing an internet host
131 referenced by name or by address, respectively. This structure contains
132 either information obtained from the name server (i.e., resolver(3) and
133 named(8)), broken-out fields from a line in /etc/hosts, or database
134 entries supplied by the yp(8) system. resolv.conf(5) describes how the
135 particular database is chosen.
138 char *h_name; /* official name of host */
139 char **h_aliases; /* alias list */
140 int h_addrtype; /* host address type */
141 int h_length; /* length of address */
142 char **h_addr_list; /* list of addresses from name server */
144 #define h_addr h_addr_list[0] /* address, for backward compatibility */
146 The members of this structure are:
148 h_name Official name of the host.
150 h_aliases A zero-terminated array of alternate names for the host.
152 h_addrtype The type of address being returned.
154 h_length The length, in bytes, of the address.
156 h_addr_list A zero-terminated array of network addresses for the host.
157 Host addresses are returned in network byte order.
159 h_addr The first address in h_addr_list; this is for backward com-
162 The function gethostbyname() will search for the named host in the cur-
163 rent domain and its parents using the search lookup semantics detailed in
164 resolv.conf(5) and hostname(7).
166 gethostbyname2() is an advanced form of gethostbyname() which allows
167 lookups in address families other than AF_INET, for example AF_INET6.
169 The gethostbyaddr() function will search for the specified address of
170 length len in the address family af. The only address family currently
171 supported is AF_INET.
173 The sethostent() function may be used to request the use of a connected
174 TCP socket for queries. If the stayopen flag is non-zero, this sets the
175 option to send all queries to the name server using TCP and to retain the
176 connection after each call to gethostbyname() or gethostbyaddr(). Other-
177 wise, queries are performed using UDP datagrams.
179 The endhostent() function closes the TCP connection.
181 The herror() function prints an error message describing the failure. If
182 its argument string is non-null, it is prepended to the message string
183 and separated from it by a colon (`:') and a space. The error message is
184 printed with a trailing newline. The contents of the error message is
185 the same as that returned by hstrerror() with argument h_errno.
192 Error return status from gethostbyname(), gethostbyname2(), and
193 gethostbyaddr() is indicated by return of a null pointer. The external
194 integer h_errno may then be checked to see whether this is a temporary
195 failure or an invalid or unknown host.
197 The variable h_errno can have the following values:
199 HOST_NOT_FOUND No such host is known.
201 TRY_AGAIN This is usually a temporary error and means that the
202 local server did not receive a response from an authori-
203 tative server. A retry at some later time may succeed.
205 NO_RECOVERY Some unexpected server failure was encountered. This is
206 a non-recoverable error.
208 NO_DATA The requested name is valid but does not have an IP
209 address; this is not a temporary error. This means that
210 the name is known to the name server but there is no
211 address associated with this name. Another type of
212 request to the name server using this domain name will
213 result in an answer; for example, a mail-forwarder may be
214 registered for this domain.
217 resolver(3), getaddrinfo(3), getnameinfo(3), hosts(5), resolv.conf(5),
218 hostname(7), named(8)
221 If the search routines in resolv.conf(5) decide to read the /etc/hosts
222 file, gethostent() and other functions will read the next line of the
223 file, re-opening the file if necessary.
225 The sethostent() function opens and/or rewinds the file /etc/hosts. If
226 the stayopen argument is non-zero, the file will not be closed after each
227 call to gethostbyname(), gethostbyname2(), or gethostbyaddr().
229 The endhostent() function closes the file.
232 The herror() function appeared in 4.3BSD. The endhostent(),
233 gethostbyaddr(), gethostbyname(), gethostent(), and sethostent() func-
234 tions appeared in 4.2BSD.
237 These functions use static data storage; if the data is needed for future
238 use, it should be copied before any subsequent calls overwrite it. Only
239 the Internet address formats are currently understood.
241 YP does not support any address families other than AF_INET and uses the
242 traditional database format.
244 BSD March 13, 1997 BSD
255 SUMMARY="Footer navigation table"
266 HREF="net-common-tcpip-manpages-getaddrinfo.html"
284 HREF="net-common-tcpip-manpages-getifaddrs.html"
300 HREF="tcpip-library-reference.html"