summaryrefslogtreecommitdiff
path: root/lib/liblwres/man/lwres_gethostent.docbook
blob: 22717821c2e817991bffd11e7ab5c4796d7e07d7 (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
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
<!--
 - Copyright (C) 2001  Internet Software Consortium.
 -
 - Permission to use, copy, modify, and distribute this software for any
 - purpose with or without fee is hereby granted, provided that the above
 - copyright notice and this permission notice appear in all copies.
 -
 - THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
 - DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 - INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 - FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 - NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-->

<!-- $Id: lwres_gethostent.docbook,v 1.1 2004/03/15 20:35:25 as Exp $ -->

<refentry>

<refentryinfo>
<date>Jun 30, 2000</date>
</refentryinfo>

<refmeta>
<refentrytitle>lwres_gethostent</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>BIND9</refmiscinfo>
</refmeta>

<refnamediv>
<refname>lwres_gethostbyname</refname>
<refname>lwres_gethostbyname2</refname>
<refname>lwres_gethostbyaddr</refname>
<refname>lwres_gethostent</refname>
<refname>lwres_sethostent</refname>
<refname>lwres_endhostent</refname>
<refname>lwres_gethostbyname_r</refname>
<refname>lwres_gethostbyaddr_r</refname>
<refname>lwres_gethostent_r</refname>
<refname>lwres_sethostent_r</refname>
<refname>lwres_endhostent_r</refname>
<refpurpose>lightweight resolver get network host entry</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include &lt;lwres/netdb.h&gt;</funcsynopsisinfo>
<funcprototype>
<funcdef>
struct hostent *
<function>lwres_gethostbyname</function></funcdef>
<paramdef>const char *name</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
struct hostent *
<function>lwres_gethostbyname2</function></funcdef>
<paramdef>const char *name</paramdef>
<paramdef>int af</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
struct hostent *
<function>lwres_gethostbyaddr</function></funcdef>
<paramdef>const char *addr</paramdef>
<paramdef>int len</paramdef>
<paramdef>int type</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
struct hostent *
<function>lwres_gethostent</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_sethostent</function></funcdef>
<paramdef>int stayopen</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_endhostent</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
struct hostent *
<function>lwres_gethostbyname_r</function></funcdef>
<paramdef>const char *name</paramdef>
<paramdef>struct hostent *resbuf</paramdef>
<paramdef>char *buf</paramdef>
<paramdef>int buflen</paramdef>
<paramdef>int *error</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
struct hostent  *
<function>lwres_gethostbyaddr_r</function></funcdef>
<paramdef>const char *addr</paramdef>
<paramdef>int len</paramdef>
<paramdef>int type</paramdef>
<paramdef>struct hostent *resbuf</paramdef>
<paramdef>char *buf</paramdef>
<paramdef>int buflen</paramdef>
<paramdef>int *error</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
struct hostent  *
<function>lwres_gethostent_r</function></funcdef>
<paramdef>struct hostent *resbuf</paramdef>
<paramdef>char *buf</paramdef>
<paramdef>int buflen</paramdef>
<paramdef>int *error</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_sethostent_r</function></funcdef>
<paramdef>int stayopen</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_endhostent_r</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>

<refsect1>
<title>DESCRIPTION</title>
<para>
These functions provide hostname-to-address and
address-to-hostname lookups by means of the lightweight resolver.
They are similar to the standard
<citerefentry>
<refentrytitle>gethostent</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>
functions provided by most operating systems.
They use a
<type>struct hostent</type>
which is usually defined in
<filename>&lt;namedb.h&gt;</filename>.

<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 */
</programlisting>
</para>
<para>
The members of this structure are:
<variablelist>
<varlistentry><term><constant>h_name</constant></term>
<listitem>
<para>
The official (canonical) name of the host.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>h_aliases</constant></term>
<listitem>
<para>
A NULL-terminated array of alternate names (nicknames) for the host.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>h_addrtype</constant></term>
<listitem>
<para>
The type of address being returned &mdash;
<type>PF_INET</type>
or
<type>PF_INET6</type>.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>h_length</constant></term>
<listitem>
<para>
The length of the address in bytes.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>h_addr_list</constant></term>
<listitem>
<para>
A <type>NULL</type>
terminated array of network addresses for the host.
Host addresses are returned in network byte order.
</para>
</listitem></varlistentry>
</variablelist>
</para>
<para>
For backward compatibility with very old software,
<constant>h_addr</constant>
is the first address in
<constant>h_addr_list.</constant>
</para>
<para>
<function>lwres_gethostent()</function>,
<function>lwres_sethostent()</function>,
<function>lwres_endhostent()</function>,
<function>lwres_gethostent_r()</function>,
<function>lwres_sethostent_r()</function>
and
<function>lwres_endhostent_r()</function>
provide iteration over the known host entries on systems that
provide such functionality through facilities like
<filename>/etc/hosts</filename>
or NIS.  The lightweight resolver does not currently implement
these functions; it only provides them as stub functions that always
return failure.
</para>

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

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

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

</refsect1>

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

<variablelist>
<varlistentry><term><constant>HOST_NOT_FOUND</constant></term>
<listitem>
<para>
The host or address was not found.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>TRY_AGAIN</constant></term>
<listitem>
<para>
A recoverable error occurred, e.g., a timeout.
Retrying the lookup may succeed.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>NO_RECOVERY</constant></term>
<listitem>
<para>
A non-recoverable error occurred.
</para>
</listitem></varlistentry>
<varlistentry><term><constant>NO_DATA</constant></term>
<listitem>
<para>
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.
</para>
</listitem></varlistentry>
</variablelist>
</para>

<para>
<citerefentry>
<refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>
translates these error codes to suitable error messages.
</para>

<para>
<function>lwres_gethostent()</function>
and
<function>lwres_gethostent_r()</function>
always return
<type>NULL</type>.
</para>

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

</refsect1>
<refsect1>
<title>SEE ALSO</title>
<para>
<citerefentry>
<refentrytitle>gethostent</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,

<citerefentry>
<refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,

<citerefentry>
<refentrytitle>lwres_hstrerror</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>
</para>
</refsect1>

<refsect1>
<title>BUGS</title>
<para>
<function>lwres_gethostbyname()</function>,
<function>lwres_gethostbyname2()</function>,
<function>lwres_gethostbyaddr()</function>
and
<function>lwres_endhostent()</function>
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
<function>lwres_gethostbyname_r()</function>,
and
<function>lwres_gethostbyaddr_r()</function>
respectively.
</para>
<para>
The resolver daemon does not currently support any non-DNS
name services such as 
<filename>/etc/hosts</filename>
or
<type>NIS</type>,
consequently the above functions don't, either.
</para>
</refsect1>
</refentry>