1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3 [<!ENTITY mdash "—">]>
5 - Copyright (C) 2004, 2005, 2007, 2012 Internet Systems Consortium, Inc. ("ISC")
6 - Copyright (C) 2001 Internet Software Consortium.
8 - Permission to use, copy, modify, and/or distribute this software for any
9 - purpose with or without fee is hereby granted, provided that the above
10 - copyright notice and this permission notice appear in all copies.
12 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
13 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18 - PERFORMANCE OF THIS SOFTWARE.
25 <date>Jun 30, 2000</date>
29 <refentrytitle>lwres_gethostent</refentrytitle>
30 <manvolnum>3</manvolnum>
31 <refmiscinfo>BIND9</refmiscinfo>
40 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
44 <holder>Internet Software Consortium.</holder>
49 <refname>lwres_gethostbyname</refname>
50 <refname>lwres_gethostbyname2</refname>
51 <refname>lwres_gethostbyaddr</refname>
52 <refname>lwres_gethostent</refname>
53 <refname>lwres_sethostent</refname>
54 <refname>lwres_endhostent</refname>
55 <refname>lwres_gethostbyname_r</refname>
56 <refname>lwres_gethostbyaddr_r</refname>
57 <refname>lwres_gethostent_r</refname>
58 <refname>lwres_sethostent_r</refname>
59 <refname>lwres_endhostent_r</refname>
60 <refpurpose>lightweight resolver get network host entry</refpurpose>
64 <funcsynopsisinfo>#include <lwres/netdb.h></funcsynopsisinfo>
68 <function>lwres_gethostbyname</function></funcdef>
69 <paramdef>const char *<parameter>name</parameter></paramdef>
74 <function>lwres_gethostbyname2</function></funcdef>
75 <paramdef>const char *<parameter>name</parameter></paramdef>
76 <paramdef>int <parameter>af</parameter></paramdef>
81 <function>lwres_gethostbyaddr</function></funcdef>
82 <paramdef>const char *<parameter>addr</parameter></paramdef>
83 <paramdef>int <parameter>len</parameter></paramdef>
84 <paramdef>int <parameter>type</parameter></paramdef>
89 <function>lwres_gethostent</function></funcdef>
90 <paramdef>void</paramdef>
95 <function>lwres_sethostent</function></funcdef>
96 <paramdef>int <parameter>stayopen</parameter></paramdef>
101 <function>lwres_endhostent</function></funcdef>
102 <paramdef>void</paramdef>
107 <function>lwres_gethostbyname_r</function></funcdef>
108 <paramdef>const char *<parameter>name</parameter></paramdef>
109 <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
110 <paramdef>char *<parameter>buf</parameter></paramdef>
111 <paramdef>int <parameter>buflen</parameter></paramdef>
112 <paramdef>int *<parameter>error</parameter></paramdef>
117 <function>lwres_gethostbyaddr_r</function></funcdef>
118 <paramdef>const char *<parameter>addr</parameter></paramdef>
119 <paramdef>int <parameter>len</parameter></paramdef>
120 <paramdef>int <parameter>type</parameter></paramdef>
121 <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
122 <paramdef>char *<parameter>buf</parameter></paramdef>
123 <paramdef>int <parameter>buflen</parameter></paramdef>
124 <paramdef>int *<parameter>error</parameter></paramdef>
129 <function>lwres_gethostent_r</function></funcdef>
130 <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
131 <paramdef>char *<parameter>buf</parameter></paramdef>
132 <paramdef>int <parameter>buflen</parameter></paramdef>
133 <paramdef>int *<parameter>error</parameter></paramdef>
138 <function>lwres_sethostent_r</function></funcdef>
139 <paramdef>int <parameter>stayopen</parameter></paramdef>
144 <function>lwres_endhostent_r</function></funcdef>
145 <paramdef>void</paramdef>
151 <title>DESCRIPTION</title>
153 These functions provide hostname-to-address and
154 address-to-hostname lookups by means of the lightweight resolver.
155 They are similar to the standard
157 <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
159 functions provided by most operating systems.
161 <type>struct hostent</type>
162 which is usually defined in
163 <filename><namedb.h></filename>.
165 <para><programlisting>
167 char *h_name; /* official name of host */
168 char **h_aliases; /* alias list */
169 int h_addrtype; /* host address type */
170 int h_length; /* length of address */
171 char **h_addr_list; /* list of addresses from name server */
173 #define h_addr h_addr_list[0] /* address, for backward compatibility */
177 The members of this structure are:
180 <term><constant>h_name</constant></term>
183 The official (canonical) name of the host.
188 <term><constant>h_aliases</constant></term>
191 A NULL-terminated array of alternate names (nicknames) for the
197 <term><constant>h_addrtype</constant></term>
200 The type of address being returned —
203 <type>PF_INET6</type>.
208 <term><constant>h_length</constant></term>
211 The length of the address in bytes.
216 <term><constant>h_addr_list</constant></term>
220 terminated array of network addresses for the host.
221 Host addresses are returned in network byte order.
228 For backward compatibility with very old software,
229 <constant>h_addr</constant>
230 is the first address in
231 <constant>h_addr_list.</constant>
233 <para><function>lwres_gethostent()</function>,
234 <function>lwres_sethostent()</function>,
235 <function>lwres_endhostent()</function>,
236 <function>lwres_gethostent_r()</function>,
237 <function>lwres_sethostent_r()</function>
239 <function>lwres_endhostent_r()</function>
240 provide iteration over the known host entries on systems that
241 provide such functionality through facilities like
242 <filename>/etc/hosts</filename>
243 or NIS. The lightweight resolver does not currently implement
244 these functions; it only provides them as stub functions that always
248 <para><function>lwres_gethostbyname()</function>
249 and <function>lwres_gethostbyname2()</function> look up the
250 hostname <parameter>name</parameter>.
251 <function>lwres_gethostbyname()</function> always looks for an
252 IPv4 address while <function>lwres_gethostbyname2()</function>
253 looks for an address of protocol family
254 <parameter>af</parameter>: either <type>PF_INET</type> or
255 <type>PF_INET6</type> — IPv4 or IPV6 addresses
256 respectively. Successful calls of the functions return a
257 <type>struct hostent</type>for the name that was looked up.
258 <type>NULL</type> is returned if the lookups by
259 <function>lwres_gethostbyname()</function> or
260 <function>lwres_gethostbyname2()</function> fail.
264 Reverse lookups of addresses are performed by
265 <function>lwres_gethostbyaddr()</function>.
266 <parameter>addr</parameter> is an address of length
267 <parameter>len</parameter> bytes and protocol family
268 <parameter>type</parameter> — <type>PF_INET</type> or
269 <type>PF_INET6</type>.
270 <function>lwres_gethostbyname_r()</function> is a
272 for forward lookups. If an error occurs, an error code is returned in
273 <parameter>*error</parameter>.
274 <parameter>resbuf</parameter> is a pointer to a
275 <type>struct hostent</type> which is initialised by a successful call to
276 <function>lwres_gethostbyname_r()</function>.
277 <parameter>buf</parameter> is a buffer of length
278 <parameter>len</parameter> bytes which is used to store the
279 <constant>h_name</constant>, <constant>h_aliases</constant>, and
280 <constant>h_addr_list</constant> elements of the
281 <type>struct hostent</type> returned in <parameter>resbuf</parameter>.
282 Successful calls to <function>lwres_gethostbyname_r()</function>
283 return <parameter>resbuf</parameter>,
284 which is a pointer to the <type>struct hostent</type> it created.
287 <para><function>lwres_gethostbyaddr_r()</function>
288 is a thread-safe function
289 that performs a reverse lookup of address <parameter>addr</parameter>
290 which is <parameter>len</parameter> bytes long and is of
292 family <parameter>type</parameter> — <type>PF_INET</type> or
293 <type>PF_INET6</type>. If an error occurs, the error code is returned
294 in <parameter>*error</parameter>. The other function
296 identical to those in <function>lwres_gethostbyname_r()</function>.
297 <parameter>resbuf</parameter> is a pointer to a
298 <type>struct hostent</type> which is initialised by a successful call to
299 <function>lwres_gethostbyaddr_r()</function>.
300 <parameter>buf</parameter> is a buffer of length
301 <parameter>len</parameter> bytes which is used to store the
302 <constant>h_name</constant>, <constant>h_aliases</constant>, and
303 <constant>h_addr_list</constant> elements of the
304 <type>struct hostent</type> returned in <parameter>resbuf</parameter>.
305 Successful calls to <function>lwres_gethostbyaddr_r()</function> return
306 <parameter>resbuf</parameter>, which is a pointer to the
307 <function>struct hostent()</function> it created.
313 <title>RETURN VALUES</title>
316 <function>lwres_gethostbyname()</function>,
317 <function>lwres_gethostbyname2()</function>,
318 <function>lwres_gethostbyaddr()</function>,
320 <function>lwres_gethostent()</function>
321 return NULL to indicate an error. In this case the global variable
322 <type>lwres_h_errno</type>
323 will contain one of the following error codes defined in
324 <filename><lwres/netdb.h></filename>:
328 <term><constant>HOST_NOT_FOUND</constant></term>
331 The host or address was not found.
336 <term><constant>TRY_AGAIN</constant></term>
339 A recoverable error occurred, e.g., a timeout.
340 Retrying the lookup may succeed.
345 <term><constant>NO_RECOVERY</constant></term>
348 A non-recoverable error occurred.
353 <term><constant>NO_DATA</constant></term>
356 The name exists, but has no address information
357 associated with it (or vice versa in the case
358 of a reverse lookup). The code NO_ADDRESS
359 is accepted as a synonym for NO_DATA for backwards
368 <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
370 translates these error codes to suitable error messages.
373 <para><function>lwres_gethostent()</function>
374 and <function>lwres_gethostent_r()</function>
375 always return <type>NULL</type>.
379 Successful calls to <function>lwres_gethostbyname_r()</function> and
380 <function>lwres_gethostbyaddr_r()</function> return
381 <parameter>resbuf</parameter>, a pointer to the
382 <type>struct hostent</type> that was initialised by these functions. They return
383 <type>NULL</type> if the lookups fail or if <parameter>buf</parameter>
384 was too small to hold the list of addresses and names referenced by
385 the <constant>h_name</constant>, <constant>h_aliases</constant>, and
386 <constant>h_addr_list</constant> elements of the
387 <type>struct hostent</type>.
388 If <parameter>buf</parameter> was too small, both
389 <function>lwres_gethostbyname_r()</function> and
390 <function>lwres_gethostbyaddr_r()</function> set the global
392 <type>errno</type> to <errorcode>ERANGE</errorcode>.
397 <title>SEE ALSO</title>
399 <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
403 <refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
407 <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
414 <para><function>lwres_gethostbyname()</function>,
415 <function>lwres_gethostbyname2()</function>,
416 <function>lwres_gethostbyaddr()</function>
418 <function>lwres_endhostent()</function>
419 are not thread safe; they return pointers to static data and
420 provide error codes through a global variable.
421 Thread-safe versions for name and address lookup are provided by
422 <function>lwres_gethostbyname_r()</function>,
424 <function>lwres_gethostbyaddr_r()</function>
428 The resolver daemon does not currently support any non-DNS
429 name services such as
430 <filename>/etc/hosts</filename>
433 consequently the above functions don't, either.