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, 2014 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.
24 <date>June 18, 2007</date>
28 <refentrytitle>lwres_gethostent</refentrytitle>
29 <manvolnum>3</manvolnum>
30 <refmiscinfo>BIND9</refmiscinfo>
39 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
43 <holder>Internet Software Consortium.</holder>
48 <refname>lwres_gethostbyname</refname>
49 <refname>lwres_gethostbyname2</refname>
50 <refname>lwres_gethostbyaddr</refname>
51 <refname>lwres_gethostent</refname>
52 <refname>lwres_sethostent</refname>
53 <refname>lwres_endhostent</refname>
54 <refname>lwres_gethostbyname_r</refname>
55 <refname>lwres_gethostbyaddr_r</refname>
56 <refname>lwres_gethostent_r</refname>
57 <refname>lwres_sethostent_r</refname>
58 <refname>lwres_endhostent_r</refname>
59 <refpurpose>lightweight resolver get network host entry</refpurpose>
63 <funcsynopsisinfo>#include <lwres/netdb.h></funcsynopsisinfo>
67 <function>lwres_gethostbyname</function></funcdef>
68 <paramdef>const char *<parameter>name</parameter></paramdef>
73 <function>lwres_gethostbyname2</function></funcdef>
74 <paramdef>const char *<parameter>name</parameter></paramdef>
75 <paramdef>int <parameter>af</parameter></paramdef>
80 <function>lwres_gethostbyaddr</function></funcdef>
81 <paramdef>const char *<parameter>addr</parameter></paramdef>
82 <paramdef>int <parameter>len</parameter></paramdef>
83 <paramdef>int <parameter>type</parameter></paramdef>
88 <function>lwres_gethostent</function></funcdef>
89 <paramdef>void</paramdef>
94 <function>lwres_sethostent</function></funcdef>
95 <paramdef>int <parameter>stayopen</parameter></paramdef>
100 <function>lwres_endhostent</function></funcdef>
101 <paramdef>void</paramdef>
106 <function>lwres_gethostbyname_r</function></funcdef>
107 <paramdef>const char *<parameter>name</parameter></paramdef>
108 <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
109 <paramdef>char *<parameter>buf</parameter></paramdef>
110 <paramdef>int <parameter>buflen</parameter></paramdef>
111 <paramdef>int *<parameter>error</parameter></paramdef>
116 <function>lwres_gethostbyaddr_r</function></funcdef>
117 <paramdef>const char *<parameter>addr</parameter></paramdef>
118 <paramdef>int <parameter>len</parameter></paramdef>
119 <paramdef>int <parameter>type</parameter></paramdef>
120 <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
121 <paramdef>char *<parameter>buf</parameter></paramdef>
122 <paramdef>int <parameter>buflen</parameter></paramdef>
123 <paramdef>int *<parameter>error</parameter></paramdef>
128 <function>lwres_gethostent_r</function></funcdef>
129 <paramdef>struct hostent *<parameter>resbuf</parameter></paramdef>
130 <paramdef>char *<parameter>buf</parameter></paramdef>
131 <paramdef>int <parameter>buflen</parameter></paramdef>
132 <paramdef>int *<parameter>error</parameter></paramdef>
137 <function>lwres_sethostent_r</function></funcdef>
138 <paramdef>int <parameter>stayopen</parameter></paramdef>
143 <function>lwres_endhostent_r</function></funcdef>
144 <paramdef>void</paramdef>
150 <title>DESCRIPTION</title>
152 These functions provide hostname-to-address and
153 address-to-hostname lookups by means of the lightweight resolver.
154 They are similar to the standard
156 <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
158 functions provided by most operating systems.
160 <type>struct hostent</type>
161 which is usually defined in
162 <filename><namedb.h></filename>.
164 <para><programlisting>
166 char *h_name; /* official name of host */
167 char **h_aliases; /* alias list */
168 int h_addrtype; /* host address type */
169 int h_length; /* length of address */
170 char **h_addr_list; /* list of addresses from name server */
172 #define h_addr h_addr_list[0] /* address, for backward compatibility */
176 The members of this structure are:
179 <term><constant>h_name</constant></term>
182 The official (canonical) name of the host.
187 <term><constant>h_aliases</constant></term>
190 A NULL-terminated array of alternate names (nicknames) for the
196 <term><constant>h_addrtype</constant></term>
199 The type of address being returned —
202 <type>PF_INET6</type>.
207 <term><constant>h_length</constant></term>
210 The length of the address in bytes.
215 <term><constant>h_addr_list</constant></term>
219 terminated array of network addresses for the host.
220 Host addresses are returned in network byte order.
227 For backward compatibility with very old software,
228 <constant>h_addr</constant>
229 is the first address in
230 <constant>h_addr_list.</constant>
232 <para><function>lwres_gethostent()</function>,
233 <function>lwres_sethostent()</function>,
234 <function>lwres_endhostent()</function>,
235 <function>lwres_gethostent_r()</function>,
236 <function>lwres_sethostent_r()</function>
238 <function>lwres_endhostent_r()</function>
239 provide iteration over the known host entries on systems that
240 provide such functionality through facilities like
241 <filename>/etc/hosts</filename>
242 or NIS. The lightweight resolver does not currently implement
243 these functions; it only provides them as stub functions that always
247 <para><function>lwres_gethostbyname()</function>
248 and <function>lwres_gethostbyname2()</function> look up the
249 hostname <parameter>name</parameter>.
250 <function>lwres_gethostbyname()</function> always looks for an
251 IPv4 address while <function>lwres_gethostbyname2()</function>
252 looks for an address of protocol family
253 <parameter>af</parameter>: either <type>PF_INET</type> or
254 <type>PF_INET6</type> — IPv4 or IPV6 addresses
255 respectively. Successful calls of the functions return a
256 <type>struct hostent</type>for the name that was looked up.
257 <type>NULL</type> is returned if the lookups by
258 <function>lwres_gethostbyname()</function> or
259 <function>lwres_gethostbyname2()</function> fail.
263 Reverse lookups of addresses are performed by
264 <function>lwres_gethostbyaddr()</function>.
265 <parameter>addr</parameter> is an address of length
266 <parameter>len</parameter> bytes and protocol family
267 <parameter>type</parameter> — <type>PF_INET</type> or
268 <type>PF_INET6</type>.
269 <function>lwres_gethostbyname_r()</function> is a
271 for forward lookups. If an error occurs, an error code is returned in
272 <parameter>*error</parameter>.
273 <parameter>resbuf</parameter> is a pointer to a
274 <type>struct hostent</type> which is initialised by a successful call to
275 <function>lwres_gethostbyname_r()</function>.
276 <parameter>buf</parameter> is a buffer of length
277 <parameter>len</parameter> bytes which is used to store the
278 <constant>h_name</constant>, <constant>h_aliases</constant>, and
279 <constant>h_addr_list</constant> elements of the
280 <type>struct hostent</type> returned in <parameter>resbuf</parameter>.
281 Successful calls to <function>lwres_gethostbyname_r()</function>
282 return <parameter>resbuf</parameter>,
283 which is a pointer to the <type>struct hostent</type> it created.
286 <para><function>lwres_gethostbyaddr_r()</function>
287 is a thread-safe function
288 that performs a reverse lookup of address <parameter>addr</parameter>
289 which is <parameter>len</parameter> bytes long and is of
291 family <parameter>type</parameter> — <type>PF_INET</type> or
292 <type>PF_INET6</type>. If an error occurs, the error code is returned
293 in <parameter>*error</parameter>. The other function
295 identical to those in <function>lwres_gethostbyname_r()</function>.
296 <parameter>resbuf</parameter> is a pointer to a
297 <type>struct hostent</type> which is initialised by a successful call to
298 <function>lwres_gethostbyaddr_r()</function>.
299 <parameter>buf</parameter> is a buffer of length
300 <parameter>len</parameter> bytes which is used to store the
301 <constant>h_name</constant>, <constant>h_aliases</constant>, and
302 <constant>h_addr_list</constant> elements of the
303 <type>struct hostent</type> returned in <parameter>resbuf</parameter>.
304 Successful calls to <function>lwres_gethostbyaddr_r()</function> return
305 <parameter>resbuf</parameter>, which is a pointer to the
306 <function>struct hostent()</function> it created.
312 <title>RETURN VALUES</title>
315 <function>lwres_gethostbyname()</function>,
316 <function>lwres_gethostbyname2()</function>,
317 <function>lwres_gethostbyaddr()</function>,
319 <function>lwres_gethostent()</function>
320 return NULL to indicate an error. In this case the global variable
321 <type>lwres_h_errno</type>
322 will contain one of the following error codes defined in
323 <filename><lwres/netdb.h></filename>:
327 <term><constant>HOST_NOT_FOUND</constant></term>
330 The host or address was not found.
335 <term><constant>TRY_AGAIN</constant></term>
338 A recoverable error occurred, e.g., a timeout.
339 Retrying the lookup may succeed.
344 <term><constant>NO_RECOVERY</constant></term>
347 A non-recoverable error occurred.
352 <term><constant>NO_DATA</constant></term>
355 The name exists, but has no address information
356 associated with it (or vice versa in the case
357 of a reverse lookup). The code NO_ADDRESS
358 is accepted as a synonym for NO_DATA for backwards
367 <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
369 translates these error codes to suitable error messages.
372 <para><function>lwres_gethostent()</function>
373 and <function>lwres_gethostent_r()</function>
374 always return <type>NULL</type>.
378 Successful calls to <function>lwres_gethostbyname_r()</function> and
379 <function>lwres_gethostbyaddr_r()</function> return
380 <parameter>resbuf</parameter>, a pointer to the
381 <type>struct hostent</type> that was initialised by these functions. They return
382 <type>NULL</type> if the lookups fail or if <parameter>buf</parameter>
383 was too small to hold the list of addresses and names referenced by
384 the <constant>h_name</constant>, <constant>h_aliases</constant>, and
385 <constant>h_addr_list</constant> elements of the
386 <type>struct hostent</type>.
387 If <parameter>buf</parameter> was too small, both
388 <function>lwres_gethostbyname_r()</function> and
389 <function>lwres_gethostbyaddr_r()</function> set the global
391 <type>errno</type> to <errorcode>ERANGE</errorcode>.
396 <title>SEE ALSO</title>
398 <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
402 <refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
406 <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3</manvolnum>
413 <para><function>lwres_gethostbyname()</function>,
414 <function>lwres_gethostbyname2()</function>,
415 <function>lwres_gethostbyaddr()</function>
417 <function>lwres_endhostent()</function>
418 are not thread safe; they return pointers to static data and
419 provide error codes through a global variable.
420 Thread-safe versions for name and address lookup are provided by
421 <function>lwres_gethostbyname_r()</function>,
423 <function>lwres_gethostbyaddr_r()</function>
427 The resolver daemon does not currently support any non-DNS
428 name services such as
429 <filename>/etc/hosts</filename>
432 consequently the above functions don't, either.