2 - Copyright (C) 2004, 2005, 2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001, 2003 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_context</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_context_create, lwres_context_destroy, lwres_context_nextserial, lwres_context_initserial, lwres_context_freemem, lwres_context_allocmem, lwres_context_sendrecv — lightweight resolver context management</p>
29 <div class="refsynopsisdiv">
31 <div class="funcsynopsis">
32 <pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre>
33 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
35 <td><code class="funcdef">
37 <b class="fsfunc">lwres_context_create</b>(</code></td>
38 <td>lwres_context_t **<var class="pdparam">contextp</var>, </td>
42 <td>void *<var class="pdparam">arg</var>, </td>
46 <td>lwres_malloc_t <var class="pdparam">malloc_function</var>, </td>
50 <td>lwres_free_t <var class="pdparam">free_function</var><code>)</code>;</td>
53 <div class="funcprototype-spacer"> </div>
54 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
55 <td><code class="funcdef">
57 <b class="fsfunc">lwres_context_destroy</b>(</code></td>
58 <td>lwres_context_t **<var class="pdparam">contextp</var><code>)</code>;</td>
60 <div class="funcprototype-spacer"> </div>
61 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
63 <td><code class="funcdef">
65 <b class="fsfunc">lwres_context_initserial</b>(</code></td>
66 <td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
70 <td>lwres_uint32_t <var class="pdparam">serial</var><code>)</code>;</td>
73 <div class="funcprototype-spacer"> </div>
74 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
75 <td><code class="funcdef">
77 <b class="fsfunc">lwres_context_nextserial</b>(</code></td>
78 <td>lwres_context_t *<var class="pdparam">ctx</var><code>)</code>;</td>
80 <div class="funcprototype-spacer"> </div>
81 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
83 <td><code class="funcdef">
85 <b class="fsfunc">lwres_context_freemem</b>(</code></td>
86 <td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
90 <td>void *<var class="pdparam">mem</var>, </td>
94 <td>size_t <var class="pdparam">len</var><code>)</code>;</td>
97 <div class="funcprototype-spacer"> </div>
98 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
100 <td><code class="funcdef">
102 <b class="fsfunc">lwres_context_allocmem</b>(</code></td>
103 <td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
107 <td>size_t <var class="pdparam">len</var><code>)</code>;</td>
110 <div class="funcprototype-spacer"> </div>
111 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
113 <td><code class="funcdef">
115 <b class="fsfunc">lwres_context_sendrecv</b>(</code></td>
116 <td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
120 <td>void *<var class="pdparam">sendbase</var>, </td>
124 <td>int <var class="pdparam">sendlen</var>, </td>
128 <td>void *<var class="pdparam">recvbase</var>, </td>
132 <td>int <var class="pdparam">recvlen</var>, </td>
136 <td>int *<var class="pdparam">recvd_len</var><code>)</code>;</td>
139 <div class="funcprototype-spacer"> </div>
142 <div class="refsection">
143 <a name="id-1.7"></a><h2>DESCRIPTION</h2>
144 <p><code class="function">lwres_context_create()</code>
145 creates a <span class="type">lwres_context_t</span> structure for use in
146 lightweight resolver operations. It holds a socket and other
147 data needed for communicating with a resolver daemon. The new
148 <span class="type">lwres_context_t</span> is returned through
149 <em class="parameter"><code>contextp</code></em>, a pointer to a
150 <span class="type">lwres_context_t</span> pointer. This
151 <span class="type">lwres_context_t</span> pointer must initially be NULL, and
152 is modified to point to the newly created
153 <span class="type">lwres_context_t</span>.
156 When the lightweight resolver needs to perform dynamic memory
157 allocation, it will call
158 <em class="parameter"><code>malloc_function</code></em>
159 to allocate memory and
160 <em class="parameter"><code>free_function</code></em>
162 <em class="parameter"><code>malloc_function</code></em>
164 <em class="parameter"><code>free_function</code></em>
165 are NULL, memory is allocated using
166 <span class="citerefentry"><span class="refentrytitle">malloc</span>(3)</span>.
168 <span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>.
170 It is not permitted to have a NULL
171 <em class="parameter"><code>malloc_function</code></em> and a non-NULL
172 <em class="parameter"><code>free_function</code></em> or vice versa.
173 <em class="parameter"><code>arg</code></em> is passed as the first parameter to
174 the memory allocation functions. If
175 <em class="parameter"><code>malloc_function</code></em> and
176 <em class="parameter"><code>free_function</code></em> are NULL,
177 <em class="parameter"><code>arg</code></em> is unused and should be passed as
181 Once memory for the structure has been allocated,
182 it is initialized using
183 <span class="citerefentry"><span class="refentrytitle">lwres_conf_init</span>(3)</span>
184 and returned via <em class="parameter"><code>*contextp</code></em>.
186 <p><code class="function">lwres_context_destroy()</code>
187 destroys a <span class="type">lwres_context_t</span>, closing its socket.
188 <em class="parameter"><code>contextp</code></em> is a pointer to a pointer to the
189 context that is to be destroyed. The pointer will be set to
190 NULL when the context has been destroyed.
193 The context holds a serial number that is used to identify
194 resolver request packets and associate responses with the
195 corresponding requests. This serial number is controlled using
196 <code class="function">lwres_context_initserial()</code> and
197 <code class="function">lwres_context_nextserial()</code>.
198 <code class="function">lwres_context_initserial()</code> sets the serial
199 number for context <em class="parameter"><code>*ctx</code></em> to
200 <em class="parameter"><code>serial</code></em>.
201 <code class="function">lwres_context_nextserial()</code> increments the
202 serial number and returns the previous value.
205 Memory for a lightweight resolver context is allocated and freed
206 using <code class="function">lwres_context_allocmem()</code> and
207 <code class="function">lwres_context_freemem()</code>. These use
208 whatever allocations were defined when the context was created
209 with <code class="function">lwres_context_create()</code>.
210 <code class="function">lwres_context_allocmem()</code> allocates
211 <em class="parameter"><code>len</code></em> bytes of memory and if successful
212 returns a pointer to the allocated storage.
213 <code class="function">lwres_context_freemem()</code> frees
214 <em class="parameter"><code>len</code></em> bytes of space starting at location
215 <em class="parameter"><code>mem</code></em>.
217 <p><code class="function">lwres_context_sendrecv()</code>
218 performs I/O for the context <em class="parameter"><code>ctx</code></em>. Data
219 are read and written from the context's socket. It writes data
220 from <em class="parameter"><code>sendbase</code></em> — typically a
221 lightweight resolver query packet — and waits for a reply
222 which is copied to the receive buffer at
223 <em class="parameter"><code>recvbase</code></em>. The number of bytes that were
224 written to this receive buffer is returned in
225 <em class="parameter"><code>*recvd_len</code></em>.
228 <div class="refsection">
229 <a name="id-1.8"></a><h2>RETURN VALUES</h2>
230 <p><code class="function">lwres_context_create()</code>
231 returns <span class="errorcode">LWRES_R_NOMEMORY</span> if memory for
232 the <span class="type">struct lwres_context</span> could not be allocated,
233 <span class="errorcode">LWRES_R_SUCCESS</span> otherwise.
236 Successful calls to the memory allocator
237 <code class="function">lwres_context_allocmem()</code>
238 return a pointer to the start of the allocated space.
239 It returns NULL if memory could not be allocated.
241 <p><span class="errorcode">LWRES_R_SUCCESS</span>
243 <code class="function">lwres_context_sendrecv()</code>
244 completes successfully.
245 <span class="errorcode">LWRES_R_IOERROR</span>
246 is returned if an I/O error occurs and
247 <span class="errorcode">LWRES_R_TIMEOUT</span>
249 <code class="function">lwres_context_sendrecv()</code>
250 times out waiting for a response.
253 <div class="refsection">
254 <a name="id-1.9"></a><h2>SEE ALSO</h2>
255 <p><span class="citerefentry"><span class="refentrytitle">lwres_conf_init</span>(3)</span>,
257 <span class="citerefentry"><span class="refentrytitle">malloc</span>(3)</span>,
259 <span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>.