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/or 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.24.418.1.8.1 2010/02/25 12:16:44 tbox 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="id2476267"></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>
38 <td>const char * </td>
40 <var class="pdparam">name</var><code>)</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>
47 <td>const char * </td>
49 <var class="pdparam">name</var>, </td>
55 <var class="pdparam">af</var><code>)</code>;</td>
58 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
60 <td><code class="funcdef">
62 <b class="fsfunc">lwres_gethostbyaddr</b>(</code></td>
63 <td>const char * </td>
65 <var class="pdparam">addr</var>, </td>
71 <var class="pdparam">len</var>, </td>
77 <var class="pdparam">type</var><code>)</code>;</td>
80 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
81 <td><code class="funcdef">
83 <b class="fsfunc">lwres_gethostent</b>(</code></td>
88 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
89 <td><code class="funcdef">
91 <b class="fsfunc">lwres_sethostent</b>(</code></td>
94 <var class="pdparam">stayopen</var><code>)</code>;</td>
96 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
97 <td><code class="funcdef">
99 <b class="fsfunc">lwres_endhostent</b>(</code></td>
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>
109 <td>const char * </td>
111 <var class="pdparam">name</var>, </td>
115 <td>struct hostent * </td>
117 <var class="pdparam">resbuf</var>, </td>
123 <var class="pdparam">buf</var>, </td>
129 <var class="pdparam">buflen</var>, </td>
135 <var class="pdparam">error</var><code>)</code>;</td>
138 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
140 <td><code class="funcdef">
142 <b class="fsfunc">lwres_gethostbyaddr_r</b>(</code></td>
143 <td>const char * </td>
145 <var class="pdparam">addr</var>, </td>
151 <var class="pdparam">len</var>, </td>
157 <var class="pdparam">type</var>, </td>
161 <td>struct hostent * </td>
163 <var class="pdparam">resbuf</var>, </td>
169 <var class="pdparam">buf</var>, </td>
175 <var class="pdparam">buflen</var>, </td>
181 <var class="pdparam">error</var><code>)</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>
189 <td>struct hostent * </td>
191 <var class="pdparam">resbuf</var>, </td>
197 <var class="pdparam">buf</var>, </td>
203 <var class="pdparam">buflen</var>, </td>
209 <var class="pdparam">error</var><code>)</code>;</td>
212 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
213 <td><code class="funcdef">
215 <b class="fsfunc">lwres_sethostent_r</b>(</code></td>
218 <var class="pdparam">stayopen</var><code>)</code>;</td>
220 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr>
221 <td><code class="funcdef">
223 <b class="fsfunc">lwres_endhostent_r</b>(</code></td>
230 <div class="refsect1" lang="en">
231 <a name="id2543606"></a><h2>DESCRIPTION</h2>
233 These functions provide hostname-to-address and
234 address-to-hostname lookups by means of the lightweight resolver.
235 They are similar to the standard
236 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>
237 functions provided by most operating systems.
239 <span class="type">struct hostent</span>
240 which is usually defined in
241 <code class="filename"><namedb.h></code>.
243 <pre class="programlisting">
245 char *h_name; /* official name of host */
246 char **h_aliases; /* alias list */
247 int h_addrtype; /* host address type */
248 int h_length; /* length of address */
249 char **h_addr_list; /* list of addresses from name server */
251 #define h_addr h_addr_list[0] /* address, for backward compatibility */
256 The members of this structure are:
258 <div class="variablelist"><dl>
259 <dt><span class="term"><code class="constant">h_name</code></span></dt>
261 The official (canonical) name of the host.
263 <dt><span class="term"><code class="constant">h_aliases</code></span></dt>
265 A NULL-terminated array of alternate names (nicknames) for the
268 <dt><span class="term"><code class="constant">h_addrtype</code></span></dt>
270 The type of address being returned —
271 <span class="type">PF_INET</span>
273 <span class="type">PF_INET6</span>.
275 <dt><span class="term"><code class="constant">h_length</code></span></dt>
277 The length of the address in bytes.
279 <dt><span class="term"><code class="constant">h_addr_list</code></span></dt>
281 A <span class="type">NULL</span>
282 terminated array of network addresses for the host.
283 Host addresses are returned in network byte order.
289 For backward compatibility with very old software,
290 <code class="constant">h_addr</code>
291 is the first address in
292 <code class="constant">h_addr_list.</code>
294 <p><code class="function">lwres_gethostent()</code>,
295 <code class="function">lwres_sethostent()</code>,
296 <code class="function">lwres_endhostent()</code>,
297 <code class="function">lwres_gethostent_r()</code>,
298 <code class="function">lwres_sethostent_r()</code>
300 <code class="function">lwres_endhostent_r()</code>
301 provide iteration over the known host entries on systems that
302 provide such functionality through facilities like
303 <code class="filename">/etc/hosts</code>
304 or NIS. The lightweight resolver does not currently implement
305 these functions; it only provides them as stub functions that always
308 <p><code class="function">lwres_gethostbyname()</code>
309 and <code class="function">lwres_gethostbyname2()</code> look up the
310 hostname <em class="parameter"><code>name</code></em>.
311 <code class="function">lwres_gethostbyname()</code> always looks for an
312 IPv4 address while <code class="function">lwres_gethostbyname2()</code>
313 looks for an address of protocol family
314 <em class="parameter"><code>af</code></em>: either <span class="type">PF_INET</span> or
315 <span class="type">PF_INET6</span> — IPv4 or IPV6 addresses
316 respectively. Successful calls of the functions return a
317 <span class="type">struct hostent</span>for the name that was looked up.
318 <span class="type">NULL</span> is returned if the lookups by
319 <code class="function">lwres_gethostbyname()</code> or
320 <code class="function">lwres_gethostbyname2()</code> fail.
323 Reverse lookups of addresses are performed by
324 <code class="function">lwres_gethostbyaddr()</code>.
325 <em class="parameter"><code>addr</code></em> is an address of length
326 <em class="parameter"><code>len</code></em> bytes and protocol family
327 <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
328 <span class="type">PF_INET6</span>.
329 <code class="function">lwres_gethostbyname_r()</code> is a
331 for forward lookups. If an error occurs, an error code is returned in
332 <em class="parameter"><code>*error</code></em>.
333 <em class="parameter"><code>resbuf</code></em> is a pointer to a
334 <span class="type">struct hostent</span> which is initialised by a successful call to
335 <code class="function">lwres_gethostbyname_r()</code>.
336 <em class="parameter"><code>buf</code></em> is a buffer of length
337 <em class="parameter"><code>len</code></em> bytes which is used to store the
338 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
339 <code class="constant">h_addr_list</code> elements of the
340 <span class="type">struct hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
341 Successful calls to <code class="function">lwres_gethostbyname_r()</code>
342 return <em class="parameter"><code>resbuf</code></em>,
343 which is a pointer to the <span class="type">struct hostent</span> it created.
345 <p><code class="function">lwres_gethostbyaddr_r()</code>
346 is a thread-safe function
347 that performs a reverse lookup of address <em class="parameter"><code>addr</code></em>
348 which is <em class="parameter"><code>len</code></em> bytes long and is of
350 family <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
351 <span class="type">PF_INET6</span>. If an error occurs, the error code is returned
352 in <em class="parameter"><code>*error</code></em>. The other function
354 identical to those in <code class="function">lwres_gethostbyname_r()</code>.
355 <em class="parameter"><code>resbuf</code></em> is a pointer to a
356 <span class="type">struct hostent</span> which is initialised by a successful call to
357 <code class="function">lwres_gethostbyaddr_r()</code>.
358 <em class="parameter"><code>buf</code></em> is a buffer of length
359 <em class="parameter"><code>len</code></em> bytes which is used to store the
360 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
361 <code class="constant">h_addr_list</code> elements of the
362 <span class="type">struct hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
363 Successful calls to <code class="function">lwres_gethostbyaddr_r()</code> return
364 <em class="parameter"><code>resbuf</code></em>, which is a pointer to the
365 <code class="function">struct hostent()</code> it created.
368 <div class="refsect1" lang="en">
369 <a name="id2543957"></a><h2>RETURN VALUES</h2>
372 <code class="function">lwres_gethostbyname()</code>,
373 <code class="function">lwres_gethostbyname2()</code>,
374 <code class="function">lwres_gethostbyaddr()</code>,
376 <code class="function">lwres_gethostent()</code>
377 return NULL to indicate an error. In this case the global variable
378 <span class="type">lwres_h_errno</span>
379 will contain one of the following error codes defined in
380 <code class="filename"><lwres/netdb.h></code>:
383 <div class="variablelist"><dl>
384 <dt><span class="term"><code class="constant">HOST_NOT_FOUND</code></span></dt>
386 The host or address was not found.
388 <dt><span class="term"><code class="constant">TRY_AGAIN</code></span></dt>
390 A recoverable error occurred, e.g., a timeout.
391 Retrying the lookup may succeed.
393 <dt><span class="term"><code class="constant">NO_RECOVERY</code></span></dt>
395 A non-recoverable error occurred.
397 <dt><span class="term"><code class="constant">NO_DATA</code></span></dt>
399 The name exists, but has no address information
400 associated with it (or vice versa in the case
401 of a reverse lookup). The code NO_ADDRESS
402 is accepted as a synonym for NO_DATA for backwards
408 <p><span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3)</span>
409 translates these error codes to suitable error messages.
411 <p><code class="function">lwres_gethostent()</code>
412 and <code class="function">lwres_gethostent_r()</code>
413 always return <span class="type">NULL</span>.
416 Successful calls to <code class="function">lwres_gethostbyname_r()</code> and
417 <code class="function">lwres_gethostbyaddr_r()</code> return
418 <em class="parameter"><code>resbuf</code></em>, a pointer to the
419 <span class="type">struct hostent</span> that was initialised by these functions. They return
420 <span class="type">NULL</span> if the lookups fail or if <em class="parameter"><code>buf</code></em>
421 was too small to hold the list of addresses and names referenced by
422 the <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
423 <code class="constant">h_addr_list</code> elements of the
424 <span class="type">struct hostent</span>.
425 If <em class="parameter"><code>buf</code></em> was too small, both
426 <code class="function">lwres_gethostbyname_r()</code> and
427 <code class="function">lwres_gethostbyaddr_r()</code> set the global
429 <span class="type">errno</span> to <span class="errorcode">ERANGE</span>.
432 <div class="refsect1" lang="en">
433 <a name="id2544190"></a><h2>SEE ALSO</h2>
434 <p><span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>,
436 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
438 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3)</span>
441 <div class="refsect1" lang="en">
442 <a name="id2544225"></a><h2>BUGS</h2>
443 <p><code class="function">lwres_gethostbyname()</code>,
444 <code class="function">lwres_gethostbyname2()</code>,
445 <code class="function">lwres_gethostbyaddr()</code>
447 <code class="function">lwres_endhostent()</code>
448 are not thread safe; they return pointers to static data and
449 provide error codes through a global variable.
450 Thread-safe versions for name and address lookup are provided by
451 <code class="function">lwres_gethostbyname_r()</code>,
453 <code class="function">lwres_gethostbyaddr_r()</code>
457 The resolver daemon does not currently support any non-DNS
458 name services such as
459 <code class="filename">/etc/hosts</code>
461 <span class="type">NIS</span>,
462 consequently the above functions don't, either.