summaryrefslogtreecommitdiff
path: root/lib/liblwres/man/lwres_context.docbook
blob: 9cdfa7525f97e7f9a2b493af4a8fd9661cf21428 (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
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
<!--
 - 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 INTERNET SOFTWARE CONSORTIUM
 - DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 - INTERNET SOFTWARE CONSORTIUM 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_context.docbook,v 1.1 2004/03/15 20:35:25 as Exp $ -->

<refentry>
<refentryinfo>


<date>Jun 30, 2000</date>
</refentryinfo>
<refmeta>
<refentrytitle>lwres_context</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>BIND9</refmiscinfo>
</refmeta>
<refnamediv>
<refname>lwres_context_create</refname>
<refname>lwres_context_destroy</refname>
<refname>lwres_context_nextserial</refname>
<refname>lwres_context_initserial</refname>
<refname>lwres_context_freemem</refname>
<refname>lwres_context_allocmem</refname>
<refname>lwres_context_sendrecv</refname>
<refpurpose>lightweight resolver context management</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include &lt;lwres/lwres.h&gt;</funcsynopsisinfo>
<funcprototype>
<funcdef>
lwres_result_t
<function>lwres_context_create</function></funcdef>
<paramdef>lwres_context_t **contextp</paramdef>
<paramdef>void *arg</paramdef>
<paramdef>lwres_malloc_t malloc_function</paramdef>
<paramdef>lwres_free_t free_function</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
lwres_result_t
<function>lwres_context_destroy</function></funcdef>
<paramdef>lwres_context_t **contextp</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_context_initserial</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
<paramdef>lwres_uint32_t serial</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
lwres_uint32_t
<function>lwres_context_nextserial</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_context_freemem</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
<paramdef>void *mem</paramdef>
<paramdef>size_t len</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void
<function>lwres_context_allocmem</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
<paramdef>size_t len</paramdef>
</funcprototype>
<funcprototype>
<funcdef>
void *
<function>lwres_context_sendrecv</function></funcdef>
<paramdef>lwres_context_t *ctx</paramdef>
<paramdef>void *sendbase</paramdef>
<paramdef>int sendlen</paramdef>
<paramdef>void *recvbase</paramdef>
<paramdef>int recvlen</paramdef>
<paramdef>int *recvd_len</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
<function>lwres_context_create()</function>
creates a
<type>lwres_context_t</type>
structure for use in lightweight resolver operations.
It holds a socket and other data needed for communicating
with a resolver daemon.
The new
<type>lwres_context_t</type>
is returned throught
<parameter>contextp</parameter>,

a pointer to a
<type>lwres_context_t</type>
pointer.  This 
<type>lwres_context_t</type>
pointer must initially be NULL, and is modified 
to point to the newly created
<type>lwres_context_t</type>.

</para>
<para>
When the lightweight resolver needs to perform dynamic memory
allocation, it will call
<parameter>malloc_function</parameter>
to allocate memory and
<parameter>free_function</parameter>

to free it.  If 
<parameter>malloc_function</parameter>
and
<parameter>free_function</parameter>

are NULL, memory is allocated using
.Xr malloc 3
and
<citerefentry>
<refentrytitle>free</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>.

It is not permitted to have a NULL
<parameter>malloc_function</parameter>
and a non-NULL
<parameter>free_function</parameter>
or vice versa.
<parameter>arg</parameter>
is passed as the first parameter to the memory
allocation functions.  
If
<parameter>malloc_function</parameter>
and
<parameter>free_function</parameter>
are NULL,
<parameter>arg</parameter>

is unused and should be passed as NULL.
</para>
<para>
Once memory for the structure has been allocated,
it is initialized using
<citerefentry>
<refentrytitle>lwres_conf_init</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>

and returned via
<parameter>*contextp</parameter>.

</para>
<para>
<function>lwres_context_destroy()</function>
destroys a 
<type>lwres_context_t</type>,

closing its socket.
<parameter>contextp</parameter>
is a pointer to a pointer to the context that is to be destroyed.
The pointer will be set to NULL when the context has been destroyed.
</para>
<para>
The context holds a serial number that is used to identify resolver
request packets and associate responses with the corresponding requests.
This serial number is controlled using
<function>lwres_context_initserial()</function>
and
<function>lwres_context_nextserial()</function>.
<function>lwres_context_initserial()</function>
sets the serial number for context
<parameter>*ctx</parameter>
to
<parameter>serial</parameter>.

<function>lwres_context_nextserial()</function>
increments the serial number and returns the previous value.
</para>
<para>
Memory for a lightweight resolver context is allocated and freed using
<function>lwres_context_allocmem()</function>
and
<function>lwres_context_freemem()</function>.
These use whatever allocations were defined when the context was
created with
<function>lwres_context_create()</function>.
<function>lwres_context_allocmem()</function>
allocates
<parameter>len</parameter>
bytes of memory and if successful returns a pointer to the allocated
storage.
<function>lwres_context_freemem()</function>
frees
<parameter>len</parameter>
bytes of space starting at location
<parameter>mem</parameter>.

</para>
<para>
<function>lwres_context_sendrecv()</function>
performs I/O for the context
<parameter>ctx</parameter>.

Data are read and written from the context's socket.
It writes data from
<parameter>sendbase</parameter>
&mdash; typically a lightweight resolver query packet &mdash;
and waits for a reply which is copied to the receive buffer at
<parameter>recvbase</parameter>.

The number of bytes that were written to this receive buffer is
returned in
<parameter>*recvd_len</parameter>.

</para>
</refsect1>
<refsect1>
<title>RETURN VALUES</title>
<para>
<function>lwres_context_create()</function>
returns
<errorcode>LWRES_R_NOMEMORY</errorcode>
if memory for the
<type>struct lwres_context</type>
could not be allocated, 
<errorcode>LWRES_R_SUCCESS</errorcode>
otherwise.
</para>
<para>
Successful calls to the memory allocator
<function>lwres_context_allocmem()</function>
return a pointer to the start of the allocated space.
It returns NULL if memory could not be allocated.
</para>
<para>
<errorcode>LWRES_R_SUCCESS</errorcode>
is returned when
<function>lwres_context_sendrecv()</function>
completes successfully.
<errorcode>LWRES_R_IOERROR</errorcode>
is returned if an I/O error occurs and
<errorcode>LWRES_R_TIMEOUT</errorcode>
is returned if
<function>lwres_context_sendrecv()</function>
times out waiting for a response.
</para>
</refsect1>
<refsect1>
<title>SEE ALSO</title>
<para>
<citerefentry>
<refentrytitle>lwres_conf_init</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,

<citerefentry>
<refentrytitle>malloc</refentrytitle><manvolnum>3</manvolnum>
</citerefentry>,

<citerefentry>
<refentrytitle>free</refentrytitle><manvolnum>3
</manvolnum>
</citerefentry>.
</para>
</refsect1>
</refentry>