summaryrefslogtreecommitdiffstats
path: root/lib/lwres/man/lwres_context.html
blob: 84fcf281041d0cbc9c8858754e80853817be15fe (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
284
285
286
287
288
289
290
291
292
293
294
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
 - Copyright (C) 2000, 2001, 2003-2005, 2007, 2014-2016, 2018, 2019 Internet Systems Consortium, Inc. ("ISC")
 - 
 - This Source Code Form is subject to the terms of the Mozilla Public
 - License, v. 2.0. If a copy of the MPL was not distributed with this
 - file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>lwres_context</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_context_create, 
    lwres_context_destroy, 
    lwres_context_nextserial, 
    lwres_context_initserial, 
    lwres_context_freemem, 
    lwres_context_allocmem, 
    lwres_context_sendrecv
     &#8212; lightweight resolver context management
  </p>
</div>
  <div class="refsynopsisdiv">
<h2>Synopsis</h2>
    <div class="funcsynopsis">
<pre class="funcsynopsisinfo">#include &lt;lwres/lwres.h&gt;</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_context_create</b>(</code></td>
<td>lwres_context_t **<var class="pdparam">contextp</var>, </td>
</tr>
<tr>
<td></td>
<td>void *<var class="pdparam">arg</var>, </td>
</tr>
<tr>
<td></td>
<td>lwres_malloc_t <var class="pdparam">malloc_function</var>, </td>
</tr>
<tr>
<td></td>
<td>lwres_free_t <var class="pdparam">free_function</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_context_destroy</b>(</code></td>
<td>lwres_context_t **<var class="pdparam">contextp</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">
void
<b class="fsfunc">lwres_context_initserial</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
</tr>
<tr>
<td></td>
<td>uint32_t <var class="pdparam">serial</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">
uint32_t
<b class="fsfunc">lwres_context_nextserial</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</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">
void
<b class="fsfunc">lwres_context_freemem</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
</tr>
<tr>
<td></td>
<td>void *<var class="pdparam">mem</var>, </td>
</tr>
<tr>
<td></td>
<td>size_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">
void
<b class="fsfunc">lwres_context_allocmem</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
</tr>
<tr>
<td></td>
<td>size_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">
void *
<b class="fsfunc">lwres_context_sendrecv</b>(</code></td>
<td>lwres_context_t *<var class="pdparam">ctx</var>, </td>
</tr>
<tr>
<td></td>
<td>void *<var class="pdparam">sendbase</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">sendlen</var>, </td>
</tr>
<tr>
<td></td>
<td>void *<var class="pdparam">recvbase</var>, </td>
</tr>
<tr>
<td></td>
<td>int <var class="pdparam">recvlen</var>, </td>
</tr>
<tr>
<td></td>
<td>int *<var class="pdparam">recvd_len</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_context_create()</code>
      creates a <span class="type">lwres_context_t</span> structure for use in
      lightweight resolver operations.  It holds a socket and other
      data needed for communicating with a resolver daemon.  The new
      <span class="type">lwres_context_t</span> is returned through
      <em class="parameter"><code>contextp</code></em>, a pointer to a
      <span class="type">lwres_context_t</span> pointer.  This
      <span class="type">lwres_context_t</span> pointer must initially be NULL, and
      is modified to point to the newly created
      <span class="type">lwres_context_t</span>.
    </p>
    <p>
      When the lightweight resolver needs to perform dynamic memory
      allocation, it will call
      <em class="parameter"><code>malloc_function</code></em>
      to allocate memory and
      <em class="parameter"><code>free_function</code></em>
      to free it.  If
      <em class="parameter"><code>malloc_function</code></em>
      and
      <em class="parameter"><code>free_function</code></em>
      are NULL, memory is allocated using
      <span class="citerefentry">
        <span class="refentrytitle">malloc</span>(3)
      </span>.
      and
      <span class="citerefentry">
        <span class="refentrytitle">free</span>(3)
      </span>.

      It is not permitted to have a NULL
      <em class="parameter"><code>malloc_function</code></em> and a non-NULL
      <em class="parameter"><code>free_function</code></em> or vice versa.
      <em class="parameter"><code>arg</code></em> is passed as the first parameter to
      the memory allocation functions.  If
      <em class="parameter"><code>malloc_function</code></em> and
      <em class="parameter"><code>free_function</code></em> are NULL,
      <em class="parameter"><code>arg</code></em> is unused and should be passed as
      NULL.
    </p>

    <p>
      Once memory for the structure has been allocated,
      it is initialized using
      <span class="citerefentry">
        <span class="refentrytitle">lwres_conf_init</span>(3)
      </span>
      and returned via <em class="parameter"><code>*contextp</code></em>.
    </p>

    <p><code class="function">lwres_context_destroy()</code>
      destroys a <span class="type">lwres_context_t</span>, closing its socket.
      <em class="parameter"><code>contextp</code></em> 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.
    </p>

    <p>
      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
      <code class="function">lwres_context_initserial()</code> and
      <code class="function">lwres_context_nextserial()</code>.
      <code class="function">lwres_context_initserial()</code> sets the serial
      number for context <em class="parameter"><code>*ctx</code></em> to
      <em class="parameter"><code>serial</code></em>.
      <code class="function">lwres_context_nextserial()</code> increments the
      serial number and returns the previous value.
    </p>

    <p>
      Memory for a lightweight resolver context is allocated and freed
      using <code class="function">lwres_context_allocmem()</code> and
      <code class="function">lwres_context_freemem()</code>.  These use
      whatever allocations were defined when the context was created
      with <code class="function">lwres_context_create()</code>.
      <code class="function">lwres_context_allocmem()</code> allocates
      <em class="parameter"><code>len</code></em> bytes of memory and if successful
      returns a pointer to the allocated storage.
      <code class="function">lwres_context_freemem()</code> frees
      <em class="parameter"><code>len</code></em> bytes of space starting at location
      <em class="parameter"><code>mem</code></em>.
    </p>

    <p><code class="function">lwres_context_sendrecv()</code>
      performs I/O for the context <em class="parameter"><code>ctx</code></em>.  Data
      are read and written from the context's socket.  It writes data
      from <em class="parameter"><code>sendbase</code></em> &#8212; typically a
      lightweight resolver query packet &#8212; and waits for a reply
      which is copied to the receive buffer at
      <em class="parameter"><code>recvbase</code></em>.  The number of bytes that were
      written to this receive buffer is returned in
      <em class="parameter"><code>*recvd_len</code></em>.
    </p>
  </div>

  <div class="refsection">
<a name="id-1.8"></a><h2>RETURN VALUES</h2>


    <p><code class="function">lwres_context_create()</code>
      returns <span class="errorcode">LWRES_R_NOMEMORY</span> if memory for
      the <span class="type">struct lwres_context</span> could not be allocated,
      <span class="errorcode">LWRES_R_SUCCESS</span> otherwise.
    </p>
    <p>
      Successful calls to the memory allocator
      <code class="function">lwres_context_allocmem()</code>
      return a pointer to the start of the allocated space.
      It returns NULL if memory could not be allocated.
    </p>
    <p><span class="errorcode">LWRES_R_SUCCESS</span>
      is returned when
      <code class="function">lwres_context_sendrecv()</code>
      completes successfully.
      <span class="errorcode">LWRES_R_IOERROR</span>
      is returned if an I/O error occurs and
      <span class="errorcode">LWRES_R_TIMEOUT</span>
      is returned if
      <code class="function">lwres_context_sendrecv()</code>
      times out waiting for a response.
    </p>
  </div>
  <div class="refsection">
<a name="id-1.9"></a><h2>SEE ALSO</h2>

    <p><span class="citerefentry">
        <span class="refentrytitle">lwres_conf_init</span>(3)
      </span>,

      <span class="citerefentry">
        <span class="refentrytitle">malloc</span>(3)
      </span>,

      <span class="citerefentry">
        <span class="refentrytitle">free</span>(3)
      </span>.
    </p>
  </div>
</div></body>
</html>