2 - Copyright (C) 2004, 2005, 2007, 2014, 2015 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.
19 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
20 <title>lwres_gethostent</title>
21 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
23 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry">
24 <a name="id-1"></a><div class="titlepage"></div>
25 <div class="refnamediv">
27 <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>
29 <div class="refsynopsisdiv">
31 <div class="funcsynopsis">
32 <pre class="funcsynopsisinfo">#include <lwres/netdb.h></pre>
33 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
34 <td><code class="funcdef">
36 <b class="fsfunc">lwres_gethostbyname</b>(</code></td>
37 <td>const char *<var class="pdparam">name</var><code>)</code>;</td>
39 <div class="funcprototype-spacer"> </div>
40 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
42 <td><code class="funcdef">
44 <b class="fsfunc">lwres_gethostbyname2</b>(</code></td>
45 <td>const char *<var class="pdparam">name</var>, </td>
49 <td>int <var class="pdparam">af</var><code>)</code>;</td>
52 <div class="funcprototype-spacer"> </div>
53 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
55 <td><code class="funcdef">
57 <b class="fsfunc">lwres_gethostbyaddr</b>(</code></td>
58 <td>const char *<var class="pdparam">addr</var>, </td>
62 <td>int <var class="pdparam">len</var>, </td>
66 <td>int <var class="pdparam">type</var><code>)</code>;</td>
69 <div class="funcprototype-spacer"> </div>
70 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
71 <td><code class="funcdef">
73 <b class="fsfunc">lwres_gethostent</b>(</code></td>
74 <td>void<code>)</code>;</td>
76 <div class="funcprototype-spacer"> </div>
77 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
78 <td><code class="funcdef">
80 <b class="fsfunc">lwres_sethostent</b>(</code></td>
81 <td>int <var class="pdparam">stayopen</var><code>)</code>;</td>
83 <div class="funcprototype-spacer"> </div>
84 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
85 <td><code class="funcdef">
87 <b class="fsfunc">lwres_endhostent</b>(</code></td>
88 <td>void<code>)</code>;</td>
90 <div class="funcprototype-spacer"> </div>
91 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
93 <td><code class="funcdef">
95 <b class="fsfunc">lwres_gethostbyname_r</b>(</code></td>
96 <td>const char *<var class="pdparam">name</var>, </td>
100 <td>struct hostent *<var class="pdparam">resbuf</var>, </td>
104 <td>char *<var class="pdparam">buf</var>, </td>
108 <td>int <var class="pdparam">buflen</var>, </td>
112 <td>int *<var class="pdparam">error</var><code>)</code>;</td>
115 <div class="funcprototype-spacer"> </div>
116 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
118 <td><code class="funcdef">
120 <b class="fsfunc">lwres_gethostbyaddr_r</b>(</code></td>
121 <td>const char *<var class="pdparam">addr</var>, </td>
125 <td>int <var class="pdparam">len</var>, </td>
129 <td>int <var class="pdparam">type</var>, </td>
133 <td>struct hostent *<var class="pdparam">resbuf</var>, </td>
137 <td>char *<var class="pdparam">buf</var>, </td>
141 <td>int <var class="pdparam">buflen</var>, </td>
145 <td>int *<var class="pdparam">error</var><code>)</code>;</td>
148 <div class="funcprototype-spacer"> </div>
149 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
151 <td><code class="funcdef">
153 <b class="fsfunc">lwres_gethostent_r</b>(</code></td>
154 <td>struct hostent *<var class="pdparam">resbuf</var>, </td>
158 <td>char *<var class="pdparam">buf</var>, </td>
162 <td>int <var class="pdparam">buflen</var>, </td>
166 <td>int *<var class="pdparam">error</var><code>)</code>;</td>
169 <div class="funcprototype-spacer"> </div>
170 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
171 <td><code class="funcdef">
173 <b class="fsfunc">lwres_sethostent_r</b>(</code></td>
174 <td>int <var class="pdparam">stayopen</var><code>)</code>;</td>
176 <div class="funcprototype-spacer"> </div>
177 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
178 <td><code class="funcdef">
180 <b class="fsfunc">lwres_endhostent_r</b>(</code></td>
181 <td>void<code>)</code>;</td>
183 <div class="funcprototype-spacer"> </div>
186 <div class="refsection">
187 <a name="id-1.7"></a><h2>DESCRIPTION</h2>
189 These functions provide hostname-to-address and
190 address-to-hostname lookups by means of the lightweight resolver.
191 They are similar to the standard
192 <span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>
193 functions provided by most operating systems.
195 <span class="type">struct hostent</span>
196 which is usually defined in
197 <code class="filename"><namedb.h></code>.
199 <pre class="programlisting">
201 char *h_name; /* official name of host */
202 char **h_aliases; /* alias list */
203 int h_addrtype; /* host address type */
204 int h_length; /* length of address */
205 char **h_addr_list; /* list of addresses from name server */
207 #define h_addr h_addr_list[0] /* address, for backward compatibility */
212 The members of this structure are:
214 <div class="variablelist"><dl class="variablelist">
215 <dt><span class="term"><code class="constant">h_name</code></span></dt>
217 The official (canonical) name of the host.
219 <dt><span class="term"><code class="constant">h_aliases</code></span></dt>
221 A NULL-terminated array of alternate names (nicknames) for the
224 <dt><span class="term"><code class="constant">h_addrtype</code></span></dt>
226 The type of address being returned —
227 <span class="type">PF_INET</span>
229 <span class="type">PF_INET6</span>.
231 <dt><span class="term"><code class="constant">h_length</code></span></dt>
233 The length of the address in bytes.
235 <dt><span class="term"><code class="constant">h_addr_list</code></span></dt>
237 A <span class="type">NULL</span>
238 terminated array of network addresses for the host.
239 Host addresses are returned in network byte order.
245 For backward compatibility with very old software,
246 <code class="constant">h_addr</code>
247 is the first address in
248 <code class="constant">h_addr_list.</code>
250 <p><code class="function">lwres_gethostent()</code>,
251 <code class="function">lwres_sethostent()</code>,
252 <code class="function">lwres_endhostent()</code>,
253 <code class="function">lwres_gethostent_r()</code>,
254 <code class="function">lwres_sethostent_r()</code>
256 <code class="function">lwres_endhostent_r()</code>
257 provide iteration over the known host entries on systems that
258 provide such functionality through facilities like
259 <code class="filename">/etc/hosts</code>
260 or NIS. The lightweight resolver does not currently implement
261 these functions; it only provides them as stub functions that always
264 <p><code class="function">lwres_gethostbyname()</code>
265 and <code class="function">lwres_gethostbyname2()</code> look up the
266 hostname <em class="parameter"><code>name</code></em>.
267 <code class="function">lwres_gethostbyname()</code> always looks for an
268 IPv4 address while <code class="function">lwres_gethostbyname2()</code>
269 looks for an address of protocol family
270 <em class="parameter"><code>af</code></em>: either <span class="type">PF_INET</span> or
271 <span class="type">PF_INET6</span> — IPv4 or IPV6 addresses
272 respectively. Successful calls of the functions return a
273 <span class="type">struct hostent</span>for the name that was looked up.
274 <span class="type">NULL</span> is returned if the lookups by
275 <code class="function">lwres_gethostbyname()</code> or
276 <code class="function">lwres_gethostbyname2()</code> fail.
279 Reverse lookups of addresses are performed by
280 <code class="function">lwres_gethostbyaddr()</code>.
281 <em class="parameter"><code>addr</code></em> is an address of length
282 <em class="parameter"><code>len</code></em> bytes and protocol family
283 <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
284 <span class="type">PF_INET6</span>.
285 <code class="function">lwres_gethostbyname_r()</code> is a
287 for forward lookups. If an error occurs, an error code is returned in
288 <em class="parameter"><code>*error</code></em>.
289 <em class="parameter"><code>resbuf</code></em> is a pointer to a
290 <span class="type">struct hostent</span> which is initialised by a successful call to
291 <code class="function">lwres_gethostbyname_r()</code>.
292 <em class="parameter"><code>buf</code></em> is a buffer of length
293 <em class="parameter"><code>len</code></em> bytes which is used to store the
294 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
295 <code class="constant">h_addr_list</code> elements of the
296 <span class="type">struct hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
297 Successful calls to <code class="function">lwres_gethostbyname_r()</code>
298 return <em class="parameter"><code>resbuf</code></em>,
299 which is a pointer to the <span class="type">struct hostent</span> it created.
301 <p><code class="function">lwres_gethostbyaddr_r()</code>
302 is a thread-safe function
303 that performs a reverse lookup of address <em class="parameter"><code>addr</code></em>
304 which is <em class="parameter"><code>len</code></em> bytes long and is of
306 family <em class="parameter"><code>type</code></em> — <span class="type">PF_INET</span> or
307 <span class="type">PF_INET6</span>. If an error occurs, the error code is returned
308 in <em class="parameter"><code>*error</code></em>. The other function
310 identical to those in <code class="function">lwres_gethostbyname_r()</code>.
311 <em class="parameter"><code>resbuf</code></em> is a pointer to a
312 <span class="type">struct hostent</span> which is initialised by a successful call to
313 <code class="function">lwres_gethostbyaddr_r()</code>.
314 <em class="parameter"><code>buf</code></em> is a buffer of length
315 <em class="parameter"><code>len</code></em> bytes which is used to store the
316 <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
317 <code class="constant">h_addr_list</code> elements of the
318 <span class="type">struct hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
319 Successful calls to <code class="function">lwres_gethostbyaddr_r()</code> return
320 <em class="parameter"><code>resbuf</code></em>, which is a pointer to the
321 <code class="function">struct hostent()</code> it created.
324 <div class="refsection">
325 <a name="id-1.8"></a><h2>RETURN VALUES</h2>
328 <code class="function">lwres_gethostbyname()</code>,
329 <code class="function">lwres_gethostbyname2()</code>,
330 <code class="function">lwres_gethostbyaddr()</code>,
332 <code class="function">lwres_gethostent()</code>
333 return NULL to indicate an error. In this case the global variable
334 <span class="type">lwres_h_errno</span>
335 will contain one of the following error codes defined in
336 <code class="filename"><lwres/netdb.h></code>:
339 <div class="variablelist"><dl class="variablelist">
340 <dt><span class="term"><code class="constant">HOST_NOT_FOUND</code></span></dt>
342 The host or address was not found.
344 <dt><span class="term"><code class="constant">TRY_AGAIN</code></span></dt>
346 A recoverable error occurred, e.g., a timeout.
347 Retrying the lookup may succeed.
349 <dt><span class="term"><code class="constant">NO_RECOVERY</code></span></dt>
351 A non-recoverable error occurred.
353 <dt><span class="term"><code class="constant">NO_DATA</code></span></dt>
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
364 <p><span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3)</span>
365 translates these error codes to suitable error messages.
367 <p><code class="function">lwres_gethostent()</code>
368 and <code class="function">lwres_gethostent_r()</code>
369 always return <span class="type">NULL</span>.
372 Successful calls to <code class="function">lwres_gethostbyname_r()</code> and
373 <code class="function">lwres_gethostbyaddr_r()</code> return
374 <em class="parameter"><code>resbuf</code></em>, a pointer to the
375 <span class="type">struct hostent</span> that was initialised by these functions. They return
376 <span class="type">NULL</span> if the lookups fail or if <em class="parameter"><code>buf</code></em>
377 was too small to hold the list of addresses and names referenced by
378 the <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
379 <code class="constant">h_addr_list</code> elements of the
380 <span class="type">struct hostent</span>.
381 If <em class="parameter"><code>buf</code></em> was too small, both
382 <code class="function">lwres_gethostbyname_r()</code> and
383 <code class="function">lwres_gethostbyaddr_r()</code> set the global
385 <span class="type">errno</span> to <span class="errorcode">ERANGE</span>.
388 <div class="refsection">
389 <a name="id-1.9"></a><h2>SEE ALSO</h2>
390 <p><span class="citerefentry"><span class="refentrytitle">gethostent</span>(3)</span>,
392 <span class="citerefentry"><span class="refentrytitle">lwres_getipnode</span>(3)</span>,
394 <span class="citerefentry"><span class="refentrytitle">lwres_hstrerror</span>(3)</span>
397 <div class="refsection">
398 <a name="id-1.10"></a><h2>BUGS</h2>
399 <p><code class="function">lwres_gethostbyname()</code>,
400 <code class="function">lwres_gethostbyname2()</code>,
401 <code class="function">lwres_gethostbyaddr()</code>
403 <code class="function">lwres_endhostent()</code>
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 <code class="function">lwres_gethostbyname_r()</code>,
409 <code class="function">lwres_gethostbyaddr_r()</code>
413 The resolver daemon does not currently support any non-DNS
414 name services such as
415 <code class="filename">/etc/hosts</code>
417 <span class="type">NIS</span>,
418 consequently the above functions don't, either.