summaryrefslogtreecommitdiffstats
path: root/contrib/bind9/lib/lwres/man/lwres_resutil.html
blob: cc45556adc44c3be0d61a06ff520fbbb0382da60 (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
<!--
 - Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
 - 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 ISC DISCLAIMS ALL WARRANTIES WITH
 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 - AND FITNESS.  IN NO EVENT SHALL ISC 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_resutil.html,v 1.8.2.1.4.2 2004/08/22 23:39:05 marka Exp $ -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>lwres_resutil</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><H1
><A
NAME="AEN1"
></A
>lwres_resutil</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN8"
></A
><H2
>Name</H2
>lwres_string_parse, lwres_addr_parse, lwres_getaddrsbyname, lwres_getnamebyaddr&nbsp;--&nbsp;lightweight resolver utility functions</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN14"
></A
><H2
>Synopsis</H2
><DIV
CLASS="FUNCSYNOPSIS"
><P
></P
><A
NAME="AEN15"
></A
><PRE
CLASS="FUNCSYNOPSISINFO"
>#include &lt;lwres/lwres.h&gt;</PRE
><P
><CODE
><CODE
CLASS="FUNCDEF"
>lwres_result_t
lwres_string_parse</CODE
>(lwres_buffer_t *b, char **c, lwres_uint16_t *len);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>lwres_result_t
lwres_addr_parse</CODE
>(lwres_buffer_t *b, lwres_addr_t *addr);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>lwres_result_t
lwres_getaddrsbyname</CODE
>(lwres_context_t *ctx, const char *name, lwres_uint32_t addrtypes, lwres_gabnresponse_t **structp);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>lwres_result_t
lwres_getnamebyaddr</CODE
>(lwres_context_t *ctx, lwres_uint32_t addrtype, lwres_uint16_t addrlen, const unsigned char *addr, lwres_gnbaresponse_t **structp);</CODE
></P
><P
></P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43"
></A
><H2
>DESCRIPTION</H2
><P
><CODE
CLASS="FUNCTION"
>lwres_string_parse()</CODE
> retrieves a DNS-encoded
string starting the current pointer of lightweight resolver buffer
<VAR
CLASS="PARAMETER"
>b</VAR
>: i.e.  <CODE
CLASS="CONSTANT"
>b-&gt;current</CODE
>.
When the function returns, the address of the first byte of the
encoded string is returned via <VAR
CLASS="PARAMETER"
>*c</VAR
> and the
length of that string is given by <VAR
CLASS="PARAMETER"
>*len</VAR
>.  The
buffer's current pointer is advanced to point at the character
following the string length, the encoded string, and the trailing
<SPAN
CLASS="TYPE"
>NULL</SPAN
> character.</P
><P
><CODE
CLASS="FUNCTION"
>lwres_addr_parse()</CODE
> extracts an address from the
buffer <VAR
CLASS="PARAMETER"
>b</VAR
>.  The buffer's current pointer
<CODE
CLASS="CONSTANT"
>b-&gt;current</CODE
> is presumed to point at an encoded
address: the address preceded by a 32-bit protocol family identifier
and a 16-bit length field.  The encoded address is copied to
<CODE
CLASS="CONSTANT"
>addr-&gt;address</CODE
> and
<CODE
CLASS="CONSTANT"
>addr-&gt;length</CODE
> indicates the size in bytes of
the address that was copied.  <CODE
CLASS="CONSTANT"
>b-&gt;current</CODE
> is
advanced to point at the next byte of available data in the buffer
following the encoded address.</P
><P
><CODE
CLASS="FUNCTION"
>lwres_getaddrsbyname()</CODE
>
and
<CODE
CLASS="FUNCTION"
>lwres_getnamebyaddr()</CODE
>
use the
<SPAN
CLASS="TYPE"
>lwres_gnbaresponse_t</SPAN
>
structure defined below:
<PRE
CLASS="PROGRAMLISTING"
>typedef struct {
        lwres_uint32_t          flags;
        lwres_uint16_t          naliases;
        lwres_uint16_t          naddrs;
        char                   *realname;
        char                  **aliases;
        lwres_uint16_t          realnamelen;
        lwres_uint16_t         *aliaslen;
        lwres_addrlist_t        addrs;
        void                   *base;
        size_t                  baselen;
} lwres_gabnresponse_t;</PRE
>
The contents of this structure are not manipulated directly but
they are controlled through the
<SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>lwres_gabn</SPAN
>(3)</SPAN
>
functions.</P
><P
>The lightweight resolver uses
<CODE
CLASS="FUNCTION"
>lwres_getaddrsbyname()</CODE
> to perform foward lookups.
Hostname <VAR
CLASS="PARAMETER"
>name</VAR
> is looked up using the resolver
context <VAR
CLASS="PARAMETER"
>ctx</VAR
> for memory allocation.
<VAR
CLASS="PARAMETER"
>addrtypes</VAR
> is a bitmask indicating which type of
addresses are to be looked up.  Current values for this bitmask are
<SPAN
CLASS="TYPE"
>LWRES_ADDRTYPE_V4</SPAN
> for IPv4 addresses and
<SPAN
CLASS="TYPE"
>LWRES_ADDRTYPE_V6</SPAN
> for IPv6 addresses.  Results of the
lookup are returned in <VAR
CLASS="PARAMETER"
>*structp</VAR
>.</P
><P
><CODE
CLASS="FUNCTION"
>lwres_getnamebyaddr()</CODE
> performs reverse lookups.
Resolver context <VAR
CLASS="PARAMETER"
>ctx</VAR
> is used for memory
allocation.  The address type is indicated by
<VAR
CLASS="PARAMETER"
>addrtype</VAR
>: <SPAN
CLASS="TYPE"
>LWRES_ADDRTYPE_V4</SPAN
> or
<SPAN
CLASS="TYPE"
>LWRES_ADDRTYPE_V6</SPAN
>.  The address to be looked up is given
by <VAR
CLASS="PARAMETER"
>addr</VAR
> and its length is
<VAR
CLASS="PARAMETER"
>addrlen</VAR
> bytes.  The result of the function call
is made available through <VAR
CLASS="PARAMETER"
>*structp</VAR
>.</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN84"
></A
><H2
>RETURN VALUES</H2
><P
>Successful calls to
<CODE
CLASS="FUNCTION"
>lwres_string_parse()</CODE
>
and
<CODE
CLASS="FUNCTION"
>lwres_addr_parse()</CODE
>
return
<SPAN
CLASS="ERRORCODE"
>LWRES_R_SUCCESS.</SPAN
>
Both functions return
<SPAN
CLASS="ERRORCODE"
>LWRES_R_FAILURE</SPAN
>
if the buffer is corrupt or
<SPAN
CLASS="ERRORCODE"
>LWRES_R_UNEXPECTEDEND</SPAN
>
if the buffer has less space than expected for the components of the
encoded string or address.</P
><P
><CODE
CLASS="FUNCTION"
>lwres_getaddrsbyname()</CODE
>
returns
<SPAN
CLASS="ERRORCODE"
>LWRES_R_SUCCESS</SPAN
>
on success and it returns
<SPAN
CLASS="ERRORCODE"
>LWRES_R_NOTFOUND</SPAN
>
if the hostname
<VAR
CLASS="PARAMETER"
>name</VAR
>
could not be found.</P
><P
><SPAN
CLASS="ERRORCODE"
>LWRES_R_SUCCESS</SPAN
>
is returned by a successful call to
<CODE
CLASS="FUNCTION"
>lwres_getnamebyaddr()</CODE
>.</P
><P
>Both
<CODE
CLASS="FUNCTION"
>lwres_getaddrsbyname()</CODE
>
and
<CODE
CLASS="FUNCTION"
>lwres_getnamebyaddr()</CODE
>
return
<SPAN
CLASS="ERRORCODE"
>LWRES_R_NOMEMORY</SPAN
>
when memory allocation requests fail and
<SPAN
CLASS="ERRORCODE"
>LWRES_R_UNEXPECTEDEND</SPAN
>
if the buffers used for sending queries and receiving replies are too
small.</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN105"
></A
><H2
>SEE ALSO</H2
><P
><SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>lwres_buffer</SPAN
>(3)</SPAN
>,

<SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>lwres_gabn</SPAN
>(3)</SPAN
>.</P
></DIV
></BODY
></HTML
>
OpenPOWER on IntegriCloud