summaryrefslogtreecommitdiffstats
path: root/lib/lwres/man/lwres_gethostent.html
blob: a67e8da6c229eb4b418f90014ab24d499559f3fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
 - Copyright (C) 2001, 2004, 2005, 2007, 2014-2016, 2018, 2019 Internet Systems Consortium, Inc. ("ISC")
 - 
 - This Source Code Form is subject to the terms of the Mozilla Public
 - License, v. 2.0. If a copy of the MPL was not distributed with this
 - file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>lwres_gethostent</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry">
<a name="id-1"></a><div class="titlepage"></div>
  
  

  

  

  <div class="refnamediv">
<h2>Name</h2>
<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
     &#8212; lightweight resolver get network host entry
  </p>
</div>
  <div class="refsynopsisdiv">
<h2>Synopsis</h2>
    <div class="funcsynopsis">
<pre class="funcsynopsisinfo">#include &lt;lwres/netdb.h&gt;</pre>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
<td><code class="funcdef">
struct hostent *
<b class="fsfunc">lwres_gethostbyname</b>(</code></td>
<td>const char *<var class="pdparam">name</var><code>)</code>;</td>
</tr></table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<tr>
<td><code class="funcdef">
struct hostent *
<b class="fsfunc">lwres_gethostbyname2</b>(</code></td>
<td>const char *<var class="pdparam">name</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">af</var><code>)</code>;</td>
</tr>
</table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<tr>
<td><code class="funcdef">
struct hostent *
<b class="fsfunc">lwres_gethostbyaddr</b>(</code></td>
<td>const char *<var class="pdparam">addr</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">len</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">type</var><code>)</code>;</td>
</tr>
</table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
<td><code class="funcdef">
struct hostent *
<b class="fsfunc">lwres_gethostent</b>(</code></td>
<td>void<code>)</code>;</td>
</tr></table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
<td><code class="funcdef">
void
<b class="fsfunc">lwres_sethostent</b>(</code></td>
<td>int <var class="pdparam">stayopen</var><code>)</code>;</td>
</tr></table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
<td><code class="funcdef">
void
<b class="fsfunc">lwres_endhostent</b>(</code></td>
<td>void<code>)</code>;</td>
</tr></table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<tr>
<td><code class="funcdef">
struct hostent *
<b class="fsfunc">lwres_gethostbyname_r</b>(</code></td>
<td>const char *<var class="pdparam">name</var>, </td>
</tr>
<tr>
<td></td>
<td>struct hostent *<var class="pdparam">resbuf</var>, </td>
</tr>
<tr>
<td></td>
<td>char *<var class="pdparam">buf</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">buflen</var>, </td>
</tr>
<tr>
<td></td>
<td>int *<var class="pdparam">error</var><code>)</code>;</td>
</tr>
</table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<tr>
<td><code class="funcdef">
struct hostent  *
<b class="fsfunc">lwres_gethostbyaddr_r</b>(</code></td>
<td>const char *<var class="pdparam">addr</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">len</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">type</var>, </td>
</tr>
<tr>
<td></td>
<td>struct hostent *<var class="pdparam">resbuf</var>, </td>
</tr>
<tr>
<td></td>
<td>char *<var class="pdparam">buf</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">buflen</var>, </td>
</tr>
<tr>
<td></td>
<td>int *<var class="pdparam">error</var><code>)</code>;</td>
</tr>
</table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<tr>
<td><code class="funcdef">
struct hostent  *
<b class="fsfunc">lwres_gethostent_r</b>(</code></td>
<td>struct hostent *<var class="pdparam">resbuf</var>, </td>
</tr>
<tr>
<td></td>
<td>char *<var class="pdparam">buf</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">buflen</var>, </td>
</tr>
<tr>
<td></td>
<td>int *<var class="pdparam">error</var><code>)</code>;</td>
</tr>
</table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
<td><code class="funcdef">
void
<b class="fsfunc">lwres_sethostent_r</b>(</code></td>
<td>int <var class="pdparam">stayopen</var><code>)</code>;</td>
</tr></table>
<div class="funcprototype-spacer"></div>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
<td><code class="funcdef">
void
<b class="fsfunc">lwres_endhostent_r</b>(</code></td>
<td>void<code>)</code>;</td>
</tr></table>
<div class="funcprototype-spacer"></div>
</div>
  </div>

  <div class="refsection">
<a name="id-1.7"></a><h2>DESCRIPTION</h2>

    <p>
      These functions provide hostname-to-address and
      address-to-hostname lookups by means of the lightweight resolver.
      They are similar to the standard
      <span class="citerefentry">
        <span class="refentrytitle">gethostent</span>(3)
      </span>
      functions provided by most operating systems.
      They use a
      <span class="type">struct hostent</span>
      which is usually defined in
      <code class="filename">&lt;namedb.h&gt;</code>.
    </p>
    <pre class="programlisting">
struct  hostent {
        char    *h_name;        /* official name of host */
        char    **h_aliases;    /* alias list */
        int     h_addrtype;     /* host address type */
        int     h_length;       /* length of address */
        char    **h_addr_list;  /* list of addresses from name server */
};
#define h_addr  h_addr_list[0]  /* address, for backward compatibility */
</pre>
<p>
    </p>
    <p>
      The members of this structure are:
      </p>
<div class="variablelist"><dl class="variablelist">
<dt><span class="term"><code class="constant">h_name</code></span></dt>
<dd>
            <p>
              The official (canonical) name of the host.
            </p>
          </dd>
<dt><span class="term"><code class="constant">h_aliases</code></span></dt>
<dd>
            <p>
              A NULL-terminated array of alternate names (nicknames) for the
              host.
            </p>
          </dd>
<dt><span class="term"><code class="constant">h_addrtype</code></span></dt>
<dd>
            <p>
              The type of address being returned &#8212;
              <span class="type">PF_INET</span>
              or
              <span class="type">PF_INET6</span>.
            </p>
          </dd>
<dt><span class="term"><code class="constant">h_length</code></span></dt>
<dd>
            <p>
              The length of the address in bytes.
            </p>
          </dd>
<dt><span class="term"><code class="constant">h_addr_list</code></span></dt>
<dd>
            <p>
              A <span class="type">NULL</span>
              terminated array of network addresses for the host.
              Host addresses are returned in network byte order.
            </p>
          </dd>
</dl></div>
<p>
    </p>
    <p>
      For backward compatibility with very old software,
      <code class="constant">h_addr</code>
      is the first address in
      <code class="constant">h_addr_list.</code>
    </p>
    <p><code class="function">lwres_gethostent()</code>,
      <code class="function">lwres_sethostent()</code>,
      <code class="function">lwres_endhostent()</code>,
      <code class="function">lwres_gethostent_r()</code>,
      <code class="function">lwres_sethostent_r()</code>
      and
      <code class="function">lwres_endhostent_r()</code>
      provide iteration over the known host entries on systems that
      provide such functionality through facilities like
      <code class="filename">/etc/hosts</code>
      or NIS.  The lightweight resolver does not currently implement
      these functions; it only provides them as stub functions that always
      return failure.
    </p>

    <p><code class="function">lwres_gethostbyname()</code>
      and <code class="function">lwres_gethostbyname2()</code> look up the
      hostname <em class="parameter"><code>name</code></em>.
      <code class="function">lwres_gethostbyname()</code> always looks for an
      IPv4 address while <code class="function">lwres_gethostbyname2()</code>
      looks for an address of protocol family
      <em class="parameter"><code>af</code></em>: either <span class="type">PF_INET</span> or
      <span class="type">PF_INET6</span> &#8212; IPv4 or IPV6 addresses
      respectively.  Successful calls of the functions return a
      <span class="type">struct hostent</span>for the name that was looked up.
      <span class="type">NULL</span> is returned if the lookups by
      <code class="function">lwres_gethostbyname()</code> or
      <code class="function">lwres_gethostbyname2()</code> fail.
    </p>

    <p>
      Reverse lookups of addresses are performed by
      <code class="function">lwres_gethostbyaddr()</code>.
      <em class="parameter"><code>addr</code></em> is an address of length
      <em class="parameter"><code>len</code></em> bytes and protocol family
      <em class="parameter"><code>type</code></em> &#8212; <span class="type">PF_INET</span> or
      <span class="type">PF_INET6</span>.
      <code class="function">lwres_gethostbyname_r()</code> is a
      thread-safe function
      for forward lookups.  If an error occurs, an error code is returned in
      <em class="parameter"><code>*error</code></em>.
      <em class="parameter"><code>resbuf</code></em> is a pointer to a
      <span class="type">struct hostent</span> which is initialised by a successful call to
      <code class="function">lwres_gethostbyname_r()</code>.
      <em class="parameter"><code>buf</code></em> is a buffer of length
      <em class="parameter"><code>len</code></em> bytes which is used to store the
      <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
      <code class="constant">h_addr_list</code> elements of the
      <span class="type">struct hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
      Successful calls to <code class="function">lwres_gethostbyname_r()</code>
      return <em class="parameter"><code>resbuf</code></em>,
      which is a pointer to the <span class="type">struct hostent</span> it created.
    </p>

    <p><code class="function">lwres_gethostbyaddr_r()</code>
      is a thread-safe function
      that performs a reverse lookup of address <em class="parameter"><code>addr</code></em>
      which is <em class="parameter"><code>len</code></em> bytes long and is of
      protocol
      family <em class="parameter"><code>type</code></em> &#8212; <span class="type">PF_INET</span> or
      <span class="type">PF_INET6</span>.  If an error occurs, the error code is returned
      in <em class="parameter"><code>*error</code></em>.  The other function
      parameters are
      identical to those in <code class="function">lwres_gethostbyname_r()</code>.
      <em class="parameter"><code>resbuf</code></em> is a pointer to a
      <span class="type">struct hostent</span> which is initialised by a successful call to
      <code class="function">lwres_gethostbyaddr_r()</code>.
      <em class="parameter"><code>buf</code></em> is a buffer of length
      <em class="parameter"><code>len</code></em> bytes which is used to store the
      <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
      <code class="constant">h_addr_list</code> elements of the
      <span class="type">struct hostent</span> returned in <em class="parameter"><code>resbuf</code></em>.
      Successful calls to <code class="function">lwres_gethostbyaddr_r()</code> return
      <em class="parameter"><code>resbuf</code></em>, which is a pointer to the
      <code class="function">struct hostent()</code> it created.
    </p>

  </div>

  <div class="refsection">
<a name="id-1.8"></a><h2>RETURN VALUES</h2>

    <p>
      The functions
      <code class="function">lwres_gethostbyname()</code>,
      <code class="function">lwres_gethostbyname2()</code>,
      <code class="function">lwres_gethostbyaddr()</code>,
      and
      <code class="function">lwres_gethostent()</code>
      return NULL to indicate an error.  In this case the global variable
      <span class="type">lwres_h_errno</span>
      will contain one of the following error codes defined in
      <code class="filename">&lt;lwres/netdb.h&gt;</code>:

      </p>
<div class="variablelist"><dl class="variablelist">
<dt><span class="term"><code class="constant">HOST_NOT_FOUND</code></span></dt>
<dd>
            <p>
              The host or address was not found.
            </p>
          </dd>
<dt><span class="term"><code class="constant">TRY_AGAIN</code></span></dt>
<dd>
            <p>
              A recoverable error occurred, e.g., a timeout.
              Retrying the lookup may succeed.
            </p>
          </dd>
<dt><span class="term"><code class="constant">NO_RECOVERY</code></span></dt>
<dd>
            <p>
              A non-recoverable error occurred.
            </p>
          </dd>
<dt><span class="term"><code class="constant">NO_DATA</code></span></dt>
<dd>
            <p>
              The name exists, but has no address information
              associated with it (or vice versa in the case
              of a reverse lookup).  The code NO_ADDRESS
              is accepted as a synonym for NO_DATA for backwards
              compatibility.
            </p>
          </dd>
</dl></div>
<p>
    </p>

    <p><span class="citerefentry">
        <span class="refentrytitle">lwres_hstrerror</span>(3)
      </span>
      translates these error codes to suitable error messages.
    </p>

    <p><code class="function">lwres_gethostent()</code>
      and <code class="function">lwres_gethostent_r()</code>
      always return <span class="type">NULL</span>.
    </p>

    <p>
      Successful calls to <code class="function">lwres_gethostbyname_r()</code> and
      <code class="function">lwres_gethostbyaddr_r()</code> return
      <em class="parameter"><code>resbuf</code></em>, a pointer to the
      <span class="type">struct hostent</span> that was initialised by these functions.  They return
      <span class="type">NULL</span> if the lookups fail or if <em class="parameter"><code>buf</code></em>
      was too small to hold the list of addresses and names referenced by
      the <code class="constant">h_name</code>, <code class="constant">h_aliases</code>, and
      <code class="constant">h_addr_list</code> elements of the
      <span class="type">struct hostent</span>.
      If <em class="parameter"><code>buf</code></em> was too small, both
      <code class="function">lwres_gethostbyname_r()</code> and
      <code class="function">lwres_gethostbyaddr_r()</code> set the global
      variable
      <span class="type">errno</span> to <span class="errorcode">ERANGE</span>.
    </p>

  </div>
  <div class="refsection">
<a name="id-1.9"></a><h2>SEE ALSO</h2>

    <p><span class="citerefentry">
        <span class="refentrytitle">gethostent</span>(3)
      </span>,

      <span class="citerefentry">
        <span class="refentrytitle">lwres_getipnode</span>(3)
      </span>,

      <span class="citerefentry">
        <span class="refentrytitle">lwres_hstrerror</span>(3)
      </span>
    </p>
  </div>

  <div class="refsection">
<a name="id-1.10"></a><h2>BUGS</h2>

    <p><code class="function">lwres_gethostbyname()</code>,
      <code class="function">lwres_gethostbyname2()</code>,
      <code class="function">lwres_gethostbyaddr()</code>
      and
      <code class="function">lwres_endhostent()</code>
      are not thread safe; they return pointers to static data and
      provide error codes through a global variable.
      Thread-safe versions for name and address lookup are provided by
      <code class="function">lwres_gethostbyname_r()</code>,
      and
      <code class="function">lwres_gethostbyaddr_r()</code>
      respectively.
    </p>
    <p>
      The resolver daemon does not currently support any non-DNS
      name services such as
      <code class="filename">/etc/hosts</code>
      or
      <span class="type">NIS</span>,
      consequently the above functions don't, either.
    </p>
  </div>
</div></body>
</html>