2 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2001 Internet Software Consortium.
5 - Permission to use, copy, modify, and distribute this software for any
6 - purpose with or without fee is hereby granted, provided that the above
7 - copyright notice and this permission notice appear in all copies.
9 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 - PERFORMANCE OF THIS SOFTWARE.
17 <!-- $Id: lwres_gethostent.html,v 1.8.2.1.4.10 2006/06/29 13:02:31 marka Exp $ -->
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres_gethostent</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2482688"></a><div class="titlepage"></div>
26 <div class="refnamediv">
28 <p>lwres_gethostbyname, lwres_gethostbyname2, lwres_gethostbyaddr, lwres_gethostent, lwres_sethostent, lwres_endhostent, lwres_gethostbyname_r, lwres_gethostbyaddr_r, lwres_gethostent_r, lwres_sethostent_r, lwres_endhostent_r — lightweight resolver get network host entry</p>
30 <div class="refsynopsisdiv">
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">#include <lwres/netdb.h></pre>
34 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
36 <td><code class="funcdef">
38 <b class="fsfunc">lwres_gethostbyname</b>(</code></td>
50 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
52 <td><code class="funcdef">
54 <b class="fsfunc">lwres_gethostbyname2</b>(</code></td>
70 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
72 <td><code class="funcdef">
74 <b class="fsfunc">lwres_gethostbyaddr</b>(</code></td>
95 <p><code class="funcdef">
97 <b class="fsfunc">lwres_gethostent</b>(</code>void<code>)</code>;</p>
98 <p><code class="funcdef">
100 <b class="fsfunc">lwres_sethostent</b>(</code>int stayopen<code>)</code>;</p>
101 <p><code class="funcdef">
103 <b class="fsfunc">lwres_endhostent</b>(</code>void<code>)</code>;</p>
104 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
106 <td><code class="funcdef">
108 <b class="fsfunc">lwres_gethostbyname_r</b>(</code></td>
139 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
141 <td><code class="funcdef">
143 <b class="fsfunc">lwres_gethostbyaddr_r</b>(</code></td>
184 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
186 <td><code class="funcdef">
188 <b class="fsfunc">lwres_gethostent_r</b>(</code></td>
214 <p><code class="funcdef">
216 <b class="fsfunc">lwres_sethostent_r</b>(</code>int stayopen<code>)</code>;</p>
217 <p><code class="funcdef">
219 <b class="fsfunc">lwres_endhostent_r</b>(</code>void<code>)</code>;</p>
222 <div class="refsect1" lang="en">
223 <a name="id2549606"></a><h2>DESCRIPTION</h2>
225 These functions provide hostname-to-address and
226 address-to-hostname lookups by means of the lightweight resolver.
227 They are similar to the standard
228 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3
230 functions provided by most operating systems.
232 <span class="type">struct hostent</span>
233 which is usually defined in
234 <code class="filename"><namedb.h></code>.
237 <pre class="programlisting">
239 char *h_name; /* official name of host */
240 char **h_aliases; /* alias list */
241 int h_addrtype; /* host address type */
242 int h_length; /* length of address */
243 char **h_addr_list; /* list of addresses from name server */
245 #define h_addr h_addr_list[0] /* address, for backward compatibility */
250 The members of this structure are:
252 <div class="variablelist"><dl>
253 <dt><span class="term"><code class="constant">h_name</code></span></dt>
255 The official (canonical) name of the host.
257 <dt><span class="term"><code class="constant">h_aliases</code></span></dt>
259 A NULL-terminated array of alternate names (nicknames) for the host.
261 <dt><span class="term"><code class="constant">h_addrtype</code></span></dt>
263 The type of address being returned —
264 <span class="type">PF_INET</span>
266 <span class="type">PF_INET6</span>.
268 <dt><span class="term"><code class="constant">h_length</code></span></dt>
270 The length of the address in bytes.
272 <dt><span class="term"><code class="constant">h_addr_list</code></span></dt>
274 A <span class="type">NULL</span>
275 terminated array of network addresses for the host.
276 Host addresses are returned in network byte order.
282 For backward compatibility with very old software,
283 <code class="constant">h_addr</code>
284 is the first address in
285 <code class="constant">h_addr_list.</code>
288 <code class="function">lwres_gethostent()</code>,
289 <code class="function">lwres_sethostent()</code>,
290 <code class="function">lwres_endhostent()</code>,
291 <code class="function">lwres_gethostent_r()</code>,
292 <code class="function">lwres_sethostent_r()</code>
294 <code class="function">lwres_endhostent_r()</code>
295 provide iteration over the known host entries on systems that
296 provide such functionality through facilities like
297 <code class="filename">/etc/hosts</code>
298 or NIS. The lightweight resolver does not currently implement
299 these functions; it only provides them as stub functions that always
303 <code class="function">lwres_gethostbyname()</code> and
304 <code class="function">lwres_gethostbyname2()</code> look up the hostname
305 <em class="parameter"><code>name</code></em>.
306 <code class="function">lwres_gethostbyname()</code> always looks for an IPv4
307 address while <code class="function">lwres_gethostbyname2()</code> looks for an
308 address of protocol family <em class="parameter"><code>af</code></em>: either
309 <span class="type">PF_INET</span> or <span class="type">PF_INET6</span> — IPv4 or IPV6
310 addresses respectively. Successful calls of the functions return a
311 <span class="type">struct hostent</span>for the name that was looked up.
312 <span class="type">NULL</span> is returned if the lookups by
313 <code class="function">lwres_gethostbyname()</code> or
314 <code class="function">lwres_gethostbyname2()</code> fail.
317 Reverse lookups of addresses are performed by
318 <code class="function">lwres_gethostbyaddr()</code>.
319 <em class="parameter"><code>addr</code></em> is an address of length
320 <em class="parameter"><code>len</code></em> bytes and protocol family
321 <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
322 <span class="type">PF_INET6</span>.
323 <code class="function">lwres_gethostbyname_r()</code> is a thread-safe function
324 for forward lookups. If an error occurs, an error code is returned in
325 <em class="parameter"><code>*error</code></em>.
326 <em class="parameter"><code>resbuf</code></em> is a pointer to a <span class="type">struct
327 hostent</span> which is initialised by a successful call to
328 <code class="function">lwres_gethostbyname_r()</code> .
329 <em class="parameter"><code>buf</code></em> is a buffer of length
330 <em class="parameter"><code>len</code></em> bytes which is used to store the
331 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
332 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
333 hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
334 Successful calls to <code class="function">lwres_gethostbyname_r()</code>
335 return <em class="parameter"><code>resbuf</code></em>,
336 which is a pointer to the <span class="type">struct hostent</span> it created.
339 <code class="function">lwres_gethostbyaddr_r()</code> is a thread-safe function
340 that performs a reverse lookup of address <em class="parameter"><code>addr</code></em>
341 which is <em class="parameter"><code>len</code></em> bytes long and is of protocol
342 family <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
343 <span class="type">PF_INET6</span>. If an error occurs, the error code is returned
344 in <em class="parameter"><code>*error</code></em>. The other function parameters are
345 identical to those in <code class="function">lwres_gethostbyname_r()</code>.
346 <em class="parameter"><code>resbuf</code></em> is a pointer to a <span class="type">struct
347 hostent</span> which is initialised by a successful call to
348 <code class="function">lwres_gethostbyaddr_r()</code>.
349 <em class="parameter"><code>buf</code></em> is a buffer of length
350 <em class="parameter"><code>len</code></em> bytes which is used to store the
351 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
352 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
353 hostent</span> returned in <em class="parameter"><code>resbuf</code></em>. Successful
354 calls to <code class="function">lwres_gethostbyaddr_r()</code> return
355 <em class="parameter"><code>resbuf</code></em>, which is a pointer to the
356 <code class="function">struct hostent()</code> it created.
359 <div class="refsect1" lang="en">
360 <a name="id2550013"></a><h2>RETURN VALUES</h2>
363 <code class="function">lwres_gethostbyname()</code>,
364 <code class="function">lwres_gethostbyname2()</code>,
365 <code class="function">lwres_gethostbyaddr()</code>,
367 <code class="function">lwres_gethostent()</code>
368 return NULL to indicate an error. In this case the global variable
369 <span class="type">lwres_h_errno</span>
370 will contain one of the following error codes defined in
371 <code class="filename"><lwres/netdb.h></code>:
374 <div class="variablelist"><dl>
375 <dt><span class="term"><code class="constant">HOST_NOT_FOUND</code></span></dt>
377 The host or address was not found.
379 <dt><span class="term"><code class="constant">TRY_AGAIN</code></span></dt>
381 A recoverable error occurred, e.g., a timeout.
382 Retrying the lookup may succeed.
384 <dt><span class="term"><code class="constant">NO_RECOVERY</code></span></dt>
386 A non-recoverable error occurred.
388 <dt><span class="term"><code class="constant">NO_DATA</code></span></dt>
390 The name exists, but has no address information
391 associated with it (or vice versa in the case
392 of a reverse lookup). The code NO_ADDRESS
393 is accepted as a synonym for NO_DATA for backwards
400 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3
402 translates these error codes to suitable error messages.
405 <code class="function">lwres_gethostent()</code>
407 <code class="function">lwres_gethostent_r()</code>
409 <span class="type">NULL</span>.
412 Successful calls to <code class="function">lwres_gethostbyname_r()</code> and
413 <code class="function">lwres_gethostbyaddr_r()</code> return
414 <em class="parameter"><code>resbuf</code></em>, a pointer to the <span class="type">struct
415 hostent</span> that was initialised by these functions. They return
416 <span class="type">NULL</span> if the lookups fail or if <em class="parameter"><code>buf</code></em>
417 was too small to hold the list of addresses and names referenced by
418 the <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
419 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
420 hostent</span>. If <em class="parameter"><code>buf</code></em> was too small, both
421 <code class="function">lwres_gethostbyname_r()</code> and
422 <code class="function">lwres_gethostbyaddr_r()</code> set the global variable
423 <span class="type">errno</span> to <span class="errorcode">ERANGE</span>.
426 <div class="refsect1" lang="en">
427 <a name="id2550173"></a><h2>SEE ALSO</h2>
429 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>,
431 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
433 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3
437 <div class="refsect1" lang="en">
438 <a name="id2550209"></a><h2>BUGS</h2>
440 <code class="function">lwres_gethostbyname()</code>,
441 <code class="function">lwres_gethostbyname2()</code>,
442 <code class="function">lwres_gethostbyaddr()</code>
444 <code class="function">lwres_endhostent()</code>
445 are not thread safe; they return pointers to static data and
446 provide error codes through a global variable.
447 Thread-safe versions for name and address lookup are provided by
448 <code class="function">lwres_gethostbyname_r()</code>,
450 <code class="function">lwres_gethostbyaddr_r()</code>
454 The resolver daemon does not currently support any non-DNS
455 name services such as
456 <code class="filename">/etc/hosts</code>
458 <span class="type">NIS</span>,
459 consequently the above functions don't, either.