2 <!ENTITY mdash "—">]>
4 - Copyright (C) 2004, 2005, 2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
5 - Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
7 - Permission to use, copy, modify, and/or distribute this software for any
8 - purpose with or without fee is hereby granted, provided that the above
9 - copyright notice and this permission notice appear in all copies.
11 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 - PERFORMANCE OF THIS SOFTWARE.
20 <!-- Converted by db4-upgrade version 1.0 -->
21 <refentry xmlns="http://docbook.org/ns/docbook" version="5.0">
23 <date>2007-06-18</date>
26 <corpname>ISC</corpname>
27 <corpauthor>Internet Systems Consortium, Inc.</corpauthor>
31 <refentrytitle>lwres_context</refentrytitle>
32 <manvolnum>3</manvolnum>
33 <refmiscinfo>BIND9</refmiscinfo>
43 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
49 <holder>Internet Software Consortium.</holder>
54 <refname>lwres_context_create</refname>
55 <refname>lwres_context_destroy</refname>
56 <refname>lwres_context_nextserial</refname>
57 <refname>lwres_context_initserial</refname>
58 <refname>lwres_context_freemem</refname>
59 <refname>lwres_context_allocmem</refname>
60 <refname>lwres_context_sendrecv</refname>
61 <refpurpose>lightweight resolver context management</refpurpose>
65 <funcsynopsisinfo>#include <lwres/lwres.h></funcsynopsisinfo>
69 <function>lwres_context_create</function></funcdef>
70 <paramdef>lwres_context_t **<parameter>contextp</parameter></paramdef>
71 <paramdef>void *<parameter>arg</parameter></paramdef>
72 <paramdef>lwres_malloc_t <parameter>malloc_function</parameter></paramdef>
73 <paramdef>lwres_free_t <parameter>free_function</parameter></paramdef>
78 <function>lwres_context_destroy</function></funcdef>
79 <paramdef>lwres_context_t **<parameter>contextp</parameter></paramdef>
84 <function>lwres_context_initserial</function></funcdef>
85 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
86 <paramdef>lwres_uint32_t <parameter>serial</parameter></paramdef>
91 <function>lwres_context_nextserial</function></funcdef>
92 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
97 <function>lwres_context_freemem</function></funcdef>
98 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
99 <paramdef>void *<parameter>mem</parameter></paramdef>
100 <paramdef>size_t <parameter>len</parameter></paramdef>
105 <function>lwres_context_allocmem</function></funcdef>
106 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
107 <paramdef>size_t <parameter>len</parameter></paramdef>
112 <function>lwres_context_sendrecv</function></funcdef>
113 <paramdef>lwres_context_t *<parameter>ctx</parameter></paramdef>
114 <paramdef>void *<parameter>sendbase</parameter></paramdef>
115 <paramdef>int <parameter>sendlen</parameter></paramdef>
116 <paramdef>void *<parameter>recvbase</parameter></paramdef>
117 <paramdef>int <parameter>recvlen</parameter></paramdef>
118 <paramdef>int *<parameter>recvd_len</parameter></paramdef>
122 <refsection><info><title>DESCRIPTION</title></info>
125 <para><function>lwres_context_create()</function>
126 creates a <type>lwres_context_t</type> structure for use in
127 lightweight resolver operations. It holds a socket and other
128 data needed for communicating with a resolver daemon. The new
129 <type>lwres_context_t</type> is returned through
130 <parameter>contextp</parameter>, a pointer to a
131 <type>lwres_context_t</type> pointer. This
132 <type>lwres_context_t</type> pointer must initially be NULL, and
133 is modified to point to the newly created
134 <type>lwres_context_t</type>.
137 When the lightweight resolver needs to perform dynamic memory
138 allocation, it will call
139 <parameter>malloc_function</parameter>
140 to allocate memory and
141 <parameter>free_function</parameter>
143 <parameter>malloc_function</parameter>
145 <parameter>free_function</parameter>
146 are NULL, memory is allocated using
148 <refentrytitle>malloc</refentrytitle><manvolnum>3</manvolnum>
152 <refentrytitle>free</refentrytitle><manvolnum>3</manvolnum>
155 It is not permitted to have a NULL
156 <parameter>malloc_function</parameter> and a non-NULL
157 <parameter>free_function</parameter> or vice versa.
158 <parameter>arg</parameter> is passed as the first parameter to
159 the memory allocation functions. If
160 <parameter>malloc_function</parameter> and
161 <parameter>free_function</parameter> are NULL,
162 <parameter>arg</parameter> is unused and should be passed as
167 Once memory for the structure has been allocated,
168 it is initialized using
170 <refentrytitle>lwres_conf_init</refentrytitle><manvolnum>3</manvolnum>
172 and returned via <parameter>*contextp</parameter>.
175 <para><function>lwres_context_destroy()</function>
176 destroys a <type>lwres_context_t</type>, closing its socket.
177 <parameter>contextp</parameter> is a pointer to a pointer to the
178 context that is to be destroyed. The pointer will be set to
179 NULL when the context has been destroyed.
183 The context holds a serial number that is used to identify
184 resolver request packets and associate responses with the
185 corresponding requests. This serial number is controlled using
186 <function>lwres_context_initserial()</function> and
187 <function>lwres_context_nextserial()</function>.
188 <function>lwres_context_initserial()</function> sets the serial
189 number for context <parameter>*ctx</parameter> to
190 <parameter>serial</parameter>.
191 <function>lwres_context_nextserial()</function> increments the
192 serial number and returns the previous value.
196 Memory for a lightweight resolver context is allocated and freed
197 using <function>lwres_context_allocmem()</function> and
198 <function>lwres_context_freemem()</function>. These use
199 whatever allocations were defined when the context was created
200 with <function>lwres_context_create()</function>.
201 <function>lwres_context_allocmem()</function> allocates
202 <parameter>len</parameter> bytes of memory and if successful
203 returns a pointer to the allocated storage.
204 <function>lwres_context_freemem()</function> frees
205 <parameter>len</parameter> bytes of space starting at location
206 <parameter>mem</parameter>.
209 <para><function>lwres_context_sendrecv()</function>
210 performs I/O for the context <parameter>ctx</parameter>. Data
211 are read and written from the context's socket. It writes data
212 from <parameter>sendbase</parameter> — typically a
213 lightweight resolver query packet — and waits for a reply
214 which is copied to the receive buffer at
215 <parameter>recvbase</parameter>. The number of bytes that were
216 written to this receive buffer is returned in
217 <parameter>*recvd_len</parameter>.
221 <refsection><info><title>RETURN VALUES</title></info>
224 <para><function>lwres_context_create()</function>
225 returns <errorcode>LWRES_R_NOMEMORY</errorcode> if memory for
226 the <type>struct lwres_context</type> could not be allocated,
227 <errorcode>LWRES_R_SUCCESS</errorcode> otherwise.
230 Successful calls to the memory allocator
231 <function>lwres_context_allocmem()</function>
232 return a pointer to the start of the allocated space.
233 It returns NULL if memory could not be allocated.
235 <para><errorcode>LWRES_R_SUCCESS</errorcode>
237 <function>lwres_context_sendrecv()</function>
238 completes successfully.
239 <errorcode>LWRES_R_IOERROR</errorcode>
240 is returned if an I/O error occurs and
241 <errorcode>LWRES_R_TIMEOUT</errorcode>
243 <function>lwres_context_sendrecv()</function>
244 times out waiting for a response.
247 <refsection><info><title>SEE ALSO</title></info>
250 <refentrytitle>lwres_conf_init</refentrytitle><manvolnum>3</manvolnum>
254 <refentrytitle>malloc</refentrytitle><manvolnum>3</manvolnum>
258 <refentrytitle>free</refentrytitle><manvolnum>3</manvolnum>