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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
- Copyright (C) 2000, 2001, 2004, 2005, 2007, 2014-2016, 2018 Internet Systems Consortium, Inc. ("ISC")
-
- Permission to use, copy, modify, and/or 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.
-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>lwres_resutil</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_string_parse,
lwres_addr_parse,
lwres_getaddrsbyname,
lwres_getnamebyaddr
— lightweight resolver utility functions
</p>
</div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<div class="funcsynopsis">
<pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre>
<table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
<tr>
<td><code class="funcdef">
lwres_result_t
<b class="fsfunc">lwres_string_parse</b>(</code></td>
<td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
</tr>
<tr>
<td> </td>
<td>char **<var class="pdparam">c</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_uint16_t *<var class="pdparam">len</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">
lwres_result_t
<b class="fsfunc">lwres_addr_parse</b>(</code></td>
<td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_addr_t *<var class="pdparam">addr</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">
lwres_result_t
<b class="fsfunc">lwres_getaddrsbyname</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
</tr>
<tr>
<td> </td>
<td>const char *<var class="pdparam">name</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_uint32_t <var class="pdparam">addrtypes</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_gabnresponse_t **<var class="pdparam">structp</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">
lwres_result_t
<b class="fsfunc">lwres_getnamebyaddr</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_uint32_t <var class="pdparam">addrtype</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_uint16_t <var class="pdparam">addrlen</var>, </td>
</tr>
<tr>
<td> </td>
<td>const unsigned char *<var class="pdparam">addr</var>, </td>
</tr>
<tr>
<td> </td>
<td>lwres_gnbaresponse_t **<var class="pdparam">structp</var><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><code class="function">lwres_string_parse()</code>
retrieves a DNS-encoded string starting the current pointer of
lightweight resolver buffer <em class="parameter"><code>b</code></em>: i.e.
<code class="constant">b->current</code>. When the function returns,
the address of the first byte of the encoded string is returned
via <em class="parameter"><code>*c</code></em> and the length of that string is
given by <em class="parameter"><code>*len</code></em>. 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 <em class="parameter"><code>b</code></em>.
The buffer's current pointer <code class="constant">b->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->address</code> and
<code class="constant">addr->length</code> indicates the size in bytes
of the address that was copied.
<code class="constant">b->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:
</p>
<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>
<p>
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
forward lookups.
Hostname <em class="parameter"><code>name</code></em> is looked up using the
resolver
context <em class="parameter"><code>ctx</code></em> for memory allocation.
<em class="parameter"><code>addrtypes</code></em> 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 <em class="parameter"><code>*structp</code></em>.
</p>
<p><code class="function">lwres_getnamebyaddr()</code>
performs reverse lookups. Resolver context
<em class="parameter"><code>ctx</code></em> is used for memory allocation. The
address type is indicated by <em class="parameter"><code>addrtype</code></em>:
<span class="type">LWRES_ADDRTYPE_V4</span> or
<span class="type">LWRES_ADDRTYPE_V6</span>. The address to be looked up is
given by <em class="parameter"><code>addr</code></em> and its length is
<em class="parameter"><code>addrlen</code></em> bytes. The result of the
function call is made available through
<em class="parameter"><code>*structp</code></em>.
</p>
</div>
<div class="refsection">
<a name="id-1.8"></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
<em class="parameter"><code>name</code></em> 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="refsection">
<a name="id-1.9"></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>
</div></body>
</html>
|