1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.0//EN"
2 "http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd"
3 [<!ENTITY mdash "—">]>
5 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
6 - Copyright (C) 2001 Internet Software Consortium.
8 - Permission to use, copy, modify, and 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.
21 <!-- $Id: lwres_gethostent.docbook,v 1.5.206.3 2005/05/13 01:22:36 marka Exp $ -->
26 <date>Jun 30, 2000</date>
30 <refentrytitle>lwres_gethostent</refentrytitle>
31 <manvolnum>3</manvolnum>
32 <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 *name</paramdef>
73 <function>lwres_gethostbyname2</function></funcdef>
74 <paramdef>const char *name</paramdef>
75 <paramdef>int af</paramdef>
80 <function>lwres_gethostbyaddr</function></funcdef>
81 <paramdef>const char *addr</paramdef>
82 <paramdef>int len</paramdef>
83 <paramdef>int type</paramdef>
88 <function>lwres_gethostent</function></funcdef>
89 <paramdef>void</paramdef>
94 <function>lwres_sethostent</function></funcdef>
95 <paramdef>int stayopen</paramdef>
100 <function>lwres_endhostent</function></funcdef>
101 <paramdef>void</paramdef>
106 <function>lwres_gethostbyname_r</function></funcdef>
107 <paramdef>const char *name</paramdef>
108 <paramdef>struct hostent *resbuf</paramdef>
109 <paramdef>char *buf</paramdef>
110 <paramdef>int buflen</paramdef>
111 <paramdef>int *error</paramdef>
116 <function>lwres_gethostbyaddr_r</function></funcdef>
117 <paramdef>const char *addr</paramdef>
118 <paramdef>int len</paramdef>
119 <paramdef>int type</paramdef>
120 <paramdef>struct hostent *resbuf</paramdef>
121 <paramdef>char *buf</paramdef>
122 <paramdef>int buflen</paramdef>
123 <paramdef>int *error</paramdef>
128 <function>lwres_gethostent_r</function></funcdef>
129 <paramdef>struct hostent *resbuf</paramdef>
130 <paramdef>char *buf</paramdef>
131 <paramdef>int buflen</paramdef>
132 <paramdef>int *error</paramdef>
137 <function>lwres_sethostent_r</function></funcdef>
138 <paramdef>int stayopen</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
159 functions provided by most operating systems.
161 <type>struct hostent</type>
162 which is usually defined in
163 <filename><namedb.h></filename>.
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:
179 <varlistentry><term><constant>h_name</constant></term>
182 The official (canonical) name of the host.
184 </listitem></varlistentry>
185 <varlistentry><term><constant>h_aliases</constant></term>
188 A NULL-terminated array of alternate names (nicknames) for the host.
190 </listitem></varlistentry>
191 <varlistentry><term><constant>h_addrtype</constant></term>
194 The type of address being returned —
197 <type>PF_INET6</type>.
199 </listitem></varlistentry>
200 <varlistentry><term><constant>h_length</constant></term>
203 The length of the address in bytes.
205 </listitem></varlistentry>
206 <varlistentry><term><constant>h_addr_list</constant></term>
210 terminated array of network addresses for the host.
211 Host addresses are returned in network byte order.
213 </listitem></varlistentry>
217 For backward compatibility with very old software,
218 <constant>h_addr</constant>
219 is the first address in
220 <constant>h_addr_list.</constant>
223 <function>lwres_gethostent()</function>,
224 <function>lwres_sethostent()</function>,
225 <function>lwres_endhostent()</function>,
226 <function>lwres_gethostent_r()</function>,
227 <function>lwres_sethostent_r()</function>
229 <function>lwres_endhostent_r()</function>
230 provide iteration over the known host entries on systems that
231 provide such functionality through facilities like
232 <filename>/etc/hosts</filename>
233 or NIS. The lightweight resolver does not currently implement
234 these functions; it only provides them as stub functions that always
239 <function>lwres_gethostbyname()</function> and
240 <function>lwres_gethostbyname2()</function> look up the hostname
241 <parameter>name</parameter>.
242 <function>lwres_gethostbyname()</function> always looks for an IPv4
243 address while <function>lwres_gethostbyname2()</function> looks for an
244 address of protocol family <parameter>af</parameter>: either
245 <type>PF_INET</type> or <type>PF_INET6</type> — IPv4 or IPV6
246 addresses respectively. Successful calls of the functions return a
247 <type>struct hostent</type>for the name that was looked up.
248 <type>NULL</type> is returned if the lookups by
249 <function>lwres_gethostbyname()</function> or
250 <function>lwres_gethostbyname2()</function> fail.
254 Reverse lookups of addresses are performed by
255 <function>lwres_gethostbyaddr()</function>.
256 <parameter>addr</parameter> is an address of length
257 <parameter>len</parameter> bytes and protocol family
258 <parameter>type</parameter> — <type>PF_INET</type> or
259 <type>PF_INET6</type>.
260 <function>lwres_gethostbyname_r()</function> is a thread-safe function
261 for forward lookups. If an error occurs, an error code is returned in
262 <parameter>*error</parameter>.
263 <parameter>resbuf</parameter> is a pointer to a <type>struct
264 hostent</type> which is initialised by a successful call to
265 <function>lwres_gethostbyname_r()</function> .
266 <parameter>buf</parameter> is a buffer of length
267 <parameter>len</parameter> bytes which is used to store the
268 <constant>h_name</constant>, <constant>h_aliases</constant>, and
269 <constant>h_addr_list</constant> elements of the <type>struct
270 hostent</type> returned in <parameter>resbuf</parameter>.
271 Successful calls to <function>lwres_gethostbyname_r()</function>
272 return <parameter>resbuf</parameter>,
273 which is a pointer to the <type>struct hostent</type> it created.
277 <function>lwres_gethostbyaddr_r()</function> is a thread-safe function
278 that performs a reverse lookup of address <parameter>addr</parameter>
279 which is <parameter>len</parameter> bytes long and is of protocol
280 family <parameter>type</parameter> — <type>PF_INET</type> or
281 <type>PF_INET6</type>. If an error occurs, the error code is returned
282 in <parameter>*error</parameter>. The other function parameters are
283 identical to those in <function>lwres_gethostbyname_r()</function>.
284 <parameter>resbuf</parameter> is a pointer to a <type>struct
285 hostent</type> which is initialised by a successful call to
286 <function>lwres_gethostbyaddr_r()</function>.
287 <parameter>buf</parameter> is a buffer of length
288 <parameter>len</parameter> bytes which is used to store the
289 <constant>h_name</constant>, <constant>h_aliases</constant>, and
290 <constant>h_addr_list</constant> elements of the <type>struct
291 hostent</type> returned in <parameter>resbuf</parameter>. Successful
292 calls to <function>lwres_gethostbyaddr_r()</function> return
293 <parameter>resbuf</parameter>, which is a pointer to the
294 <function>struct hostent()</function> it created.
300 <title>RETURN VALUES</title>
303 <function>lwres_gethostbyname()</function>,
304 <function>lwres_gethostbyname2()</function>,
305 <function>lwres_gethostbyaddr()</function>,
307 <function>lwres_gethostent()</function>
308 return NULL to indicate an error. In this case the global variable
309 <type>lwres_h_errno</type>
310 will contain one of the following error codes defined in
311 <filename><lwres/netdb.h></filename>:
314 <varlistentry><term><constant>HOST_NOT_FOUND</constant></term>
317 The host or address was not found.
319 </listitem></varlistentry>
320 <varlistentry><term><constant>TRY_AGAIN</constant></term>
323 A recoverable error occurred, e.g., a timeout.
324 Retrying the lookup may succeed.
326 </listitem></varlistentry>
327 <varlistentry><term><constant>NO_RECOVERY</constant></term>
330 A non-recoverable error occurred.
332 </listitem></varlistentry>
333 <varlistentry><term><constant>NO_DATA</constant></term>
336 The name exists, but has no address information
337 associated with it (or vice versa in the case
338 of a reverse lookup). The code NO_ADDRESS
339 is accepted as a synonym for NO_DATA for backwards
342 </listitem></varlistentry>
348 <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3
351 translates these error codes to suitable error messages.
355 <function>lwres_gethostent()</function>
357 <function>lwres_gethostent_r()</function>
363 Successful calls to <function>lwres_gethostbyname_r()</function> and
364 <function>lwres_gethostbyaddr_r()</function> return
365 <parameter>resbuf</parameter>, a pointer to the <type>struct
366 hostent</type> that was initialised by these functions. They return
367 <type>NULL</type> if the lookups fail or if <parameter>buf</parameter>
368 was too small to hold the list of addresses and names referenced by
369 the <constant>h_name</constant>, <constant>h_aliases</constant>, and
370 <constant>h_addr_list</constant> elements of the <type>struct
371 hostent</type>. If <parameter>buf</parameter> was too small, both
372 <function>lwres_gethostbyname_r()</function> and
373 <function>lwres_gethostbyaddr_r()</function> set the global variable
374 <type>errno</type> to <errorcode>ERANGE</errorcode>.
379 <title>SEE ALSO</title>
382 <refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
386 <refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
390 <refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3
399 <function>lwres_gethostbyname()</function>,
400 <function>lwres_gethostbyname2()</function>,
401 <function>lwres_gethostbyaddr()</function>
403 <function>lwres_endhostent()</function>
404 are not thread safe; they return pointers to static data and
405 provide error codes through a global variable.
406 Thread-safe versions for name and address lookup are provided by
407 <function>lwres_gethostbyname_r()</function>,
409 <function>lwres_gethostbyaddr_r()</function>
413 The resolver daemon does not currently support any non-DNS
414 name services such as
415 <filename>/etc/hosts</filename>
418 consequently the above functions don't, either.