2 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
5 - Permission to use, copy, modify, and 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.
17 <!-- $Id: lwres_context.html,v 1.5.2.2.2.10 2005/10/13 02:33:55 marka Exp $ -->
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres_context</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2463721"></a><div class="titlepage"></div>
26 <div class="refnamediv">
28 <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>
30 <div class="refsynopsisdiv">
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">#include <lwres/lwres.h></pre>
34 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
36 <td><code class="funcdef">
38 <b class="fsfunc">lwres_context_create</b>(</code></td>
59 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
60 <td><code class="funcdef">
62 <b class="fsfunc">lwres_context_destroy</b>(</code></td>
67 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
69 <td><code class="funcdef">
71 <b class="fsfunc">lwres_context_initserial</b>(</code></td>
82 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
83 <td><code class="funcdef">
85 <b class="fsfunc">lwres_context_nextserial</b>(</code></td>
90 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
92 <td><code class="funcdef">
94 <b class="fsfunc">lwres_context_freemem</b>(</code></td>
110 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
112 <td><code class="funcdef">
114 <b class="fsfunc">lwres_context_allocmem</b>(</code></td>
125 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
127 <td><code class="funcdef">
129 <b class="fsfunc">lwres_context_sendrecv</b>(</code></td>
162 <div class="refsect1" lang="en">
163 <a name="id2525975"></a><h2>DESCRIPTION</h2>
165 <code class="function">lwres_context_create()</code>
167 <span class="type">lwres_context_t</span>
168 structure for use in lightweight resolver operations.
169 It holds a socket and other data needed for communicating
170 with a resolver daemon.
172 <span class="type">lwres_context_t</span>
174 <em class="parameter"><code>contextp</code></em>,
177 <span class="type">lwres_context_t</span>
179 <span class="type">lwres_context_t</span>
180 pointer must initially be NULL, and is modified
181 to point to the newly created
182 <span class="type">lwres_context_t</span>.
186 When the lightweight resolver needs to perform dynamic memory
187 allocation, it will call
188 <em class="parameter"><code>malloc_function</code></em>
189 to allocate memory and
190 <em class="parameter"><code>free_function</code></em>
193 <em class="parameter"><code>malloc_function</code></em>
195 <em class="parameter"><code>free_function</code></em>
197 are NULL, memory is allocated using
200 <span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>.
202 It is not permitted to have a NULL
203 <em class="parameter"><code>malloc_function</code></em>
205 <em class="parameter"><code>free_function</code></em>
207 <em class="parameter"><code>arg</code></em>
208 is passed as the first parameter to the memory
209 allocation functions.
211 <em class="parameter"><code>malloc_function</code></em>
213 <em class="parameter"><code>free_function</code></em>
215 <em class="parameter"><code>arg</code></em>
217 is unused and should be passed as NULL.
220 Once memory for the structure has been allocated,
221 it is initialized using
222 <span class="citerefentry"><span class="refentrytitle">lwres_conf_init</span>(3)</span>
225 <em class="parameter"><code>*contextp</code></em>.
229 <code class="function">lwres_context_destroy()</code>
231 <span class="type">lwres_context_t</span>,
234 <em class="parameter"><code>contextp</code></em>
235 is a pointer to a pointer to the context that is to be destroyed.
236 The pointer will be set to NULL when the context has been destroyed.
239 The context holds a serial number that is used to identify resolver
240 request packets and associate responses with the corresponding requests.
241 This serial number is controlled using
242 <code class="function">lwres_context_initserial()</code>
244 <code class="function">lwres_context_nextserial()</code>.
245 <code class="function">lwres_context_initserial()</code>
246 sets the serial number for context
247 <em class="parameter"><code>*ctx</code></em>
249 <em class="parameter"><code>serial</code></em>.
251 <code class="function">lwres_context_nextserial()</code>
252 increments the serial number and returns the previous value.
255 Memory for a lightweight resolver context is allocated and freed using
256 <code class="function">lwres_context_allocmem()</code>
258 <code class="function">lwres_context_freemem()</code>.
259 These use whatever allocations were defined when the context was
261 <code class="function">lwres_context_create()</code>.
262 <code class="function">lwres_context_allocmem()</code>
264 <em class="parameter"><code>len</code></em>
265 bytes of memory and if successful returns a pointer to the allocated
267 <code class="function">lwres_context_freemem()</code>
269 <em class="parameter"><code>len</code></em>
270 bytes of space starting at location
271 <em class="parameter"><code>mem</code></em>.
275 <code class="function">lwres_context_sendrecv()</code>
276 performs I/O for the context
277 <em class="parameter"><code>ctx</code></em>.
279 Data are read and written from the context's socket.
281 <em class="parameter"><code>sendbase</code></em>
282 — typically a lightweight resolver query packet —
283 and waits for a reply which is copied to the receive buffer at
284 <em class="parameter"><code>recvbase</code></em>.
286 The number of bytes that were written to this receive buffer is
288 <em class="parameter"><code>*recvd_len</code></em>.
292 <div class="refsect1" lang="en">
293 <a name="id2526156"></a><h2>RETURN VALUES</h2>
295 <code class="function">lwres_context_create()</code>
297 <span class="errorcode">LWRES_R_NOMEMORY</span>
299 <span class="type">struct lwres_context</span>
300 could not be allocated,
301 <span class="errorcode">LWRES_R_SUCCESS</span>
305 Successful calls to the memory allocator
306 <code class="function">lwres_context_allocmem()</code>
307 return a pointer to the start of the allocated space.
308 It returns NULL if memory could not be allocated.
311 <span class="errorcode">LWRES_R_SUCCESS</span>
313 <code class="function">lwres_context_sendrecv()</code>
314 completes successfully.
315 <span class="errorcode">LWRES_R_IOERROR</span>
316 is returned if an I/O error occurs and
317 <span class="errorcode">LWRES_R_TIMEOUT</span>
319 <code class="function">lwres_context_sendrecv()</code>
320 times out waiting for a response.
323 <div class="refsect1" lang="en">
324 <a name="id2526208"></a><h2>SEE ALSO</h2>
326 <span class="citerefentry"><span class="refentrytitle">lwres_conf_init</span>(3)</span>,
328 <span class="citerefentry"><span class="refentrytitle">malloc</span>(3)</span>,
330 <span class="citerefentry"><span class="refentrytitle">free</span>(3