2 - Copyright (C) 2004, 2005, 2007 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.13 2007/01/30 00:11:48 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.71.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2476275"></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"><tr>
35 <td><code class="funcdef">
37 <b class="fsfunc">lwres_gethostbyname</b>(</code></td>
42 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
44 <td><code class="funcdef">
46 <b class="fsfunc">lwres_gethostbyname2</b>(</code></td>
57 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
59 <td><code class="funcdef">
61 <b class="fsfunc">lwres_gethostbyaddr</b>(</code></td>
77 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
78 <td><code class="funcdef">
80 <b class="fsfunc">lwres_gethostent</b>(</code></td>
85 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
86 <td><code class="funcdef">
88 <b class="fsfunc">lwres_sethostent</b>(</code></td>
93 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
94 <td><code class="funcdef">
96 <b class="fsfunc">lwres_endhostent</b>(</code></td>
101 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
103 <td><code class="funcdef">
105 <b class="fsfunc">lwres_gethostbyname_r</b>(</code></td>
131 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
133 <td><code class="funcdef">
135 <b class="fsfunc">lwres_gethostbyaddr_r</b>(</code></td>
171 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
173 <td><code class="funcdef">
175 <b class="fsfunc">lwres_gethostent_r</b>(</code></td>
196 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
197 <td><code class="funcdef">
199 <b class="fsfunc">lwres_sethostent_r</b>(</code></td>
204 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr>
205 <td><code class="funcdef">
207 <b class="fsfunc">lwres_endhostent_r</b>(</code></td>
214 <div class="refsect1" lang="en">
215 <a name="id2543547"></a><h2>DESCRIPTION</h2>
217 These functions provide hostname-to-address and
218 address-to-hostname lookups by means of the lightweight resolver.
219 They are similar to the standard
220 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3
222 functions provided by most operating systems.
224 <span class="type">struct hostent</span>
225 which is usually defined in
226 <code class="filename"><namedb.h></code>.
229 <pre class="programlisting">
231 char *h_name; /* official name of host */
232 char **h_aliases; /* alias list */
233 int h_addrtype; /* host address type */
234 int h_length; /* length of address */
235 char **h_addr_list; /* list of addresses from name server */
237 #define h_addr h_addr_list[0] /* address, for backward compatibility */
242 The members of this structure are:
244 <div class="variablelist"><dl>
245 <dt><span class="term"><code class="constant">h_name</code></span></dt>
247 The official (canonical) name of the host.
249 <dt><span class="term"><code class="constant">h_aliases</code></span></dt>
251 A NULL-terminated array of alternate names (nicknames) for the host.
253 <dt><span class="term"><code class="constant">h_addrtype</code></span></dt>
255 The type of address being returned —
256 <span class="type">PF_INET</span>
258 <span class="type">PF_INET6</span>.
260 <dt><span class="term"><code class="constant">h_length</code></span></dt>
262 The length of the address in bytes.
264 <dt><span class="term"><code class="constant">h_addr_list</code></span></dt>
266 A <span class="type">NULL</span>
267 terminated array of network addresses for the host.
268 Host addresses are returned in network byte order.
274 For backward compatibility with very old software,
275 <code class="constant">h_addr</code>
276 is the first address in
277 <code class="constant">h_addr_list.</code>
280 <code class="function">lwres_gethostent()</code>,
281 <code class="function">lwres_sethostent()</code>,
282 <code class="function">lwres_endhostent()</code>,
283 <code class="function">lwres_gethostent_r()</code>,
284 <code class="function">lwres_sethostent_r()</code>
286 <code class="function">lwres_endhostent_r()</code>
287 provide iteration over the known host entries on systems that
288 provide such functionality through facilities like
289 <code class="filename">/etc/hosts</code>
290 or NIS. The lightweight resolver does not currently implement
291 these functions; it only provides them as stub functions that always
295 <code class="function">lwres_gethostbyname()</code> and
296 <code class="function">lwres_gethostbyname2()</code> look up the hostname
297 <em class="parameter"><code>name</code></em>.
298 <code class="function">lwres_gethostbyname()</code> always looks for an IPv4
299 address while <code class="function">lwres_gethostbyname2()</code> looks for an
300 address of protocol family <em class="parameter"><code>af</code></em>: either
301 <span class="type">PF_INET</span> or <span class="type">PF_INET6</span> — IPv4 or IPV6
302 addresses respectively. Successful calls of the functions return a
303 <span class="type">struct hostent</span>for the name that was looked up.
304 <span class="type">NULL</span> is returned if the lookups by
305 <code class="function">lwres_gethostbyname()</code> or
306 <code class="function">lwres_gethostbyname2()</code> fail.
309 Reverse lookups of addresses are performed by
310 <code class="function">lwres_gethostbyaddr()</code>.
311 <em class="parameter"><code>addr</code></em> is an address of length
312 <em class="parameter"><code>len</code></em> bytes and protocol family
313 <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
314 <span class="type">PF_INET6</span>.
315 <code class="function">lwres_gethostbyname_r()</code> is a thread-safe function
316 for forward lookups. If an error occurs, an error code is returned in
317 <em class="parameter"><code>*error</code></em>.
318 <em class="parameter"><code>resbuf</code></em> is a pointer to a <span class="type">struct
319 hostent</span> which is initialised by a successful call to
320 <code class="function">lwres_gethostbyname_r()</code> .
321 <em class="parameter"><code>buf</code></em> is a buffer of length
322 <em class="parameter"><code>len</code></em> bytes which is used to store the
323 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
324 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
325 hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
326 Successful calls to <code class="function">lwres_gethostbyname_r()</code>
327 return <em class="parameter"><code>resbuf</code></em>,
328 which is a pointer to the <span class="type">struct hostent</span> it created.
331 <code class="function">lwres_gethostbyaddr_r()</code> is a thread-safe function
332 that performs a reverse lookup of address <em class="parameter"><code>addr</code></em>
333 which is <em class="parameter"><code>len</code></em> bytes long and is of protocol
334 family <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
335 <span class="type">PF_INET6</span>. If an error occurs, the error code is returned
336 in <em class="parameter"><code>*error</code></em>. The other function parameters are
337 identical to those in <code class="function">lwres_gethostbyname_r()</code>.
338 <em class="parameter"><code>resbuf</code></em> is a pointer to a <span class="type">struct
339 hostent</span> which is initialised by a successful call to
340 <code class="function">lwres_gethostbyaddr_r()</code>.
341 <em class="parameter"><code>buf</code></em> is a buffer of length
342 <em class="parameter"><code>len</code></em> bytes which is used to store the
343 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
344 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
345 hostent</span> returned in <em class="parameter"><code>resbuf</code></em>. Successful
346 calls to <code class="function">lwres_gethostbyaddr_r()</code> return
347 <em class="parameter"><code>resbuf</code></em>, which is a pointer to the
348 <code class="function">struct hostent()</code> it created.
351 <div class="refsect1" lang="en">
352 <a name="id2543886"></a><h2>RETURN VALUES</h2>
355 <code class="function">lwres_gethostbyname()</code>,
356 <code class="function">lwres_gethostbyname2()</code>,
357 <code class="function">lwres_gethostbyaddr()</code>,
359 <code class="function">lwres_gethostent()</code>
360 return NULL to indicate an error. In this case the global variable
361 <span class="type">lwres_h_errno</span>
362 will contain one of the following error codes defined in
363 <code class="filename"><lwres/netdb.h></code>:
366 <div class="variablelist"><dl>
367 <dt><span class="term"><code class="constant">HOST_NOT_FOUND</code></span></dt>
369 The host or address was not found.
371 <dt><span class="term"><code class="constant">TRY_AGAIN</code></span></dt>
373 A recoverable error occurred, e.g., a timeout.
374 Retrying the lookup may succeed.
376 <dt><span class="term"><code class="constant">NO_RECOVERY</code></span></dt>
378 A non-recoverable error occurred.
380 <dt><span class="term"><code class="constant">NO_DATA</code></span></dt>
382 The name exists, but has no address information
383 associated with it (or vice versa in the case
384 of a reverse lookup). The code NO_ADDRESS
385 is accepted as a synonym for NO_DATA for backwards
392 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3
394 translates these error codes to suitable error messages.
397 <code class="function">lwres_gethostent()</code>
399 <code class="function">lwres_gethostent_r()</code>
401 <span class="type">NULL</span>.
404 Successful calls to <code class="function">lwres_gethostbyname_r()</code> and
405 <code class="function">lwres_gethostbyaddr_r()</code> return
406 <em class="parameter"><code>resbuf</code></em>, a pointer to the <span class="type">struct
407 hostent</span> that was initialised by these functions. They return
408 <span class="type">NULL</span> if the lookups fail or if <em class="parameter"><code>buf</code></em>
409 was too small to hold the list of addresses and names referenced by
410 the <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
411 <code class="constant">h_addr_list</code> elements of the <span class="type">struct
412 hostent</span>. If <em class="parameter"><code>buf</code></em> was too small, both
413 <code class="function">lwres_gethostbyname_r()</code> and
414 <code class="function">lwres_gethostbyaddr_r()</code> set the global variable
415 <span class="type">errno</span> to <span class="errorcode">ERANGE</span>.
418 <div class="refsect1" lang="en">
419 <a name="id2544046"></a><h2>SEE ALSO</h2>
421 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>,
423 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
425 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3
429 <div class="refsect1" lang="en">
430 <a name="id2544082"></a><h2>BUGS</h2>
432 <code class="function">lwres_gethostbyname()</code>,
433 <code class="function">lwres_gethostbyname2()</code>,
434 <code class="function">lwres_gethostbyaddr()</code>
436 <code class="function">lwres_endhostent()</code>
437 are not thread safe; they return pointers to static data and
438 provide error codes through a global variable.
439 Thread-safe versions for name and address lookup are provided by
440 <code class="function">lwres_gethostbyname_r()</code>,
442 <code class="function">lwres_gethostbyaddr_r()</code>
446 The resolver daemon does not currently support any non-DNS
447 name services such as
448 <code class="filename">/etc/hosts</code>
450 <span class="type">NIS</span>,
451 consequently the above functions don't, either.