2 - Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001 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.
20 <meta http-equiv=
"Content-Type" content=
"text/html; charset=ISO-8859-1">
21 <title>lwres_buffer
</title>
22 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.71.1">
24 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF"><div class=
"refentry" lang=
"en">
25 <a name=
"id2476275"></a><div class=
"titlepage"></div>
26 <div class=
"refnamediv">
28 <p>lwres_buffer_init, lwres_buffer_invalidate, lwres_buffer_add, lwres_buffer_subtract, lwres_buffer_clear, lwres_buffer_first, lwres_buffer_forward, lwres_buffer_back, lwres_buffer_getuint8, lwres_buffer_putuint8, lwres_buffer_getuint16, lwres_buffer_putuint16, lwres_buffer_getuint32, lwres_buffer_putuint32, lwres_buffer_putmem, lwres_buffer_getmem
— lightweight resolver buffer management
</p>
30 <div class=
"refsynopsisdiv">
32 <div class=
"funcsynopsis">
33 <pre class=
"funcsynopsisinfo">
34 #include
<lwres/lwbuffer.h
>
36 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
38 <td><code class=
"funcdef">
40 <b class=
"fsfunc">lwres_buffer_init
</b>(
</code></td>
41 <td>lwres_buffer_t *
</td>
43 <var class=
"pdparam">b
</var>,
</td>
49 <var class=
"pdparam">base
</var>,
</td>
53 <td>unsigned int
</td>
55 <var class=
"pdparam">length
</var><code>)
</code>;
</td>
58 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em"><tr>
59 <td><code class=
"funcdef">
61 <b class=
"fsfunc">lwres_buffer_invalidate
</b>(
</code></td>
62 <td>lwres_buffer_t *
</td>
64 <var class=
"pdparam">b
</var><code>)
</code>;
</td>
66 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
68 <td><code class=
"funcdef">
70 <b class=
"fsfunc">lwres_buffer_add
</b>(
</code></td>
71 <td>lwres_buffer_t *
</td>
73 <var class=
"pdparam">b
</var>,
</td>
77 <td>unsigned int
</td>
79 <var class=
"pdparam">n
</var><code>)
</code>;
</td>
82 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
84 <td><code class=
"funcdef">
86 <b class=
"fsfunc">lwres_buffer_subtract
</b>(
</code></td>
87 <td>lwres_buffer_t *
</td>
89 <var class=
"pdparam">b
</var>,
</td>
93 <td>unsigned int
</td>
95 <var class=
"pdparam">n
</var><code>)
</code>;
</td>
98 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em"><tr>
99 <td><code class=
"funcdef">
101 <b class=
"fsfunc">lwres_buffer_clear
</b>(
</code></td>
102 <td>lwres_buffer_t *
</td>
104 <var class=
"pdparam">b
</var><code>)
</code>;
</td>
106 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em"><tr>
107 <td><code class=
"funcdef">
109 <b class=
"fsfunc">lwres_buffer_first
</b>(
</code></td>
110 <td>lwres_buffer_t *
</td>
112 <var class=
"pdparam">b
</var><code>)
</code>;
</td>
114 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
116 <td><code class=
"funcdef">
118 <b class=
"fsfunc">lwres_buffer_forward
</b>(
</code></td>
119 <td>lwres_buffer_t *
</td>
121 <var class=
"pdparam">b
</var>,
</td>
125 <td>unsigned int
</td>
127 <var class=
"pdparam">n
</var><code>)
</code>;
</td>
130 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
132 <td><code class=
"funcdef">
134 <b class=
"fsfunc">lwres_buffer_back
</b>(
</code></td>
135 <td>lwres_buffer_t *
</td>
137 <var class=
"pdparam">b
</var>,
</td>
141 <td>unsigned int
</td>
143 <var class=
"pdparam">n
</var><code>)
</code>;
</td>
146 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em"><tr>
147 <td><code class=
"funcdef">
149 <b class=
"fsfunc">lwres_buffer_getuint8
</b>(
</code></td>
150 <td>lwres_buffer_t *
</td>
152 <var class=
"pdparam">b
</var><code>)
</code>;
</td>
154 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
156 <td><code class=
"funcdef">
158 <b class=
"fsfunc">lwres_buffer_putuint8
</b>(
</code></td>
159 <td>lwres_buffer_t *
</td>
161 <var class=
"pdparam">b
</var>,
</td>
165 <td>lwres_uint8_t
</td>
167 <var class=
"pdparam">val
</var><code>)
</code>;
</td>
170 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em"><tr>
171 <td><code class=
"funcdef">
173 <b class=
"fsfunc">lwres_buffer_getuint16
</b>(
</code></td>
174 <td>lwres_buffer_t *
</td>
176 <var class=
"pdparam">b
</var><code>)
</code>;
</td>
178 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
180 <td><code class=
"funcdef">
182 <b class=
"fsfunc">lwres_buffer_putuint16
</b>(
</code></td>
183 <td>lwres_buffer_t *
</td>
185 <var class=
"pdparam">b
</var>,
</td>
189 <td>lwres_uint16_t
</td>
191 <var class=
"pdparam">val
</var><code>)
</code>;
</td>
194 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em"><tr>
195 <td><code class=
"funcdef">
197 <b class=
"fsfunc">lwres_buffer_getuint32
</b>(
</code></td>
198 <td>lwres_buffer_t *
</td>
200 <var class=
"pdparam">b
</var><code>)
</code>;
</td>
202 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
204 <td><code class=
"funcdef">
206 <b class=
"fsfunc">lwres_buffer_putuint32
</b>(
</code></td>
207 <td>lwres_buffer_t *
</td>
209 <var class=
"pdparam">b
</var>,
</td>
213 <td>lwres_uint32_t
</td>
215 <var class=
"pdparam">val
</var><code>)
</code>;
</td>
218 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0" style=
"padding-bottom: 1em">
220 <td><code class=
"funcdef">
222 <b class=
"fsfunc">lwres_buffer_putmem
</b>(
</code></td>
223 <td>lwres_buffer_t *
</td>
225 <var class=
"pdparam">b
</var>,
</td>
229 <td>const unsigned char *
</td>
231 <var class=
"pdparam">base
</var>,
</td>
235 <td>unsigned int
</td>
237 <var class=
"pdparam">length
</var><code>)
</code>;
</td>
240 <table border=
"0" summary=
"Function synopsis" cellspacing=
"0" cellpadding=
"0">
242 <td><code class=
"funcdef">
244 <b class=
"fsfunc">lwres_buffer_getmem
</b>(
</code></td>
245 <td>lwres_buffer_t *
</td>
247 <var class=
"pdparam">b
</var>,
</td>
251 <td>unsigned char *
</td>
253 <var class=
"pdparam">base
</var>,
</td>
257 <td>unsigned int
</td>
259 <var class=
"pdparam">length
</var><code>)
</code>;
</td>
264 <div class=
"refsect1" lang=
"en">
265 <a name=
"id2543901"></a><h2>DESCRIPTION
</h2>
267 These functions provide bounds checked access to a region of memory
268 where data is being read or written.
269 They are based on, and similar to, the
270 <code class=
"literal">isc_buffer_
</code>
271 functions in the ISC library.
274 A buffer is a region of memory, together with a set of related
276 The
<span class=
"emphasis"><em>used region
</em></span> and the
277 <span class=
"emphasis"><em>available
</em></span> region are disjoint, and
278 their union is the buffer's region.
279 The used region extends from the beginning of the buffer region to the
281 The available region extends from one byte greater than the last used
282 byte to the end of the buffer's region.
283 The size of the used region can be changed using various
285 Initially, the used region is empty.
288 The used region is further subdivided into two disjoint regions: the
289 <span class=
"emphasis"><em>consumed region
</em></span> and the
<span class=
"emphasis"><em>remaining region
</em></span>.
290 The union of these two regions is the used region.
291 The consumed region extends from the beginning of the used region to
292 the byte before the
<span class=
"emphasis"><em>current
</em></span> offset (if any).
293 The
<span class=
"emphasis"><em>remaining
</em></span> region the current pointer to the end
296 The size of the consumed region can be changed using various
298 Initially, the consumed region is empty.
301 The
<span class=
"emphasis"><em>active region
</em></span> is an (optional) subregion of the
304 It extends from the current offset to an offset in the
306 Initially, the active region is empty.
307 If the current offset advances beyond the chosen offset,
308 the active region will also be empty.
310 <pre class=
"programlisting">
311 /------------entire length---------------\\
312 /----- used region -----\\/-- available --\\
313 +----------------------------------------+
314 | consumed | remaining | |
315 +----------------------------------------+
320 <pre class=
"programlisting">
322 b == current pointer. Can be anywhere between a and d.
323 c == active pointer. Meaningful between b and d.
325 e == length of buffer.
329 <pre class=
"programlisting">
330 a-e == entire length of buffer.
332 a-b == consumed region.
333 b-d == remaining region.
334 b-c == optional active region.
338 <p><code class=
"function">lwres_buffer_init()
</code>
340 <span class=
"type">lwres_buffer_t
</span>
341 <em class=
"parameter"><code>*b
</code></em>
342 and assocates it with the memory region of size
343 <em class=
"parameter"><code>length
</code></em>
344 bytes starting at location
345 <em class=
"parameter"><code>base.
</code></em>
347 <p><code class=
"function">lwres_buffer_invalidate()
</code>
348 marks the buffer
<em class=
"parameter"><code>*b
</code></em>
349 as invalid. Invalidating a buffer after use is not required,
350 but makes it possible to catch its possible accidental use.
354 <code class=
"function">lwres_buffer_add()
</code>
356 <code class=
"function">lwres_buffer_subtract()
</code>
357 respectively increase and decrease the used space in
359 <em class=
"parameter"><code>*b
</code></em>
361 <em class=
"parameter"><code>n
</code></em>
363 <code class=
"function">lwres_buffer_add()
</code>
364 checks for buffer overflow and
365 <code class=
"function">lwres_buffer_subtract()
</code>
366 checks for underflow.
367 These functions do not allocate or deallocate memory.
368 They just change the value of
369 <em class=
"structfield"><code>used
</code></em>.
372 A buffer is re-initialised by
373 <code class=
"function">lwres_buffer_clear()
</code>.
375 <em class=
"structfield"><code>used
</code></em>,
376 <em class=
"structfield"><code>current
</code></em>
378 <em class=
"structfield"><code>active
</code></em>
381 <p><code class=
"function">lwres_buffer_first
</code>
382 makes the consumed region of buffer
383 <em class=
"parameter"><code>*p
</code></em>
385 <em class=
"structfield"><code>current
</code></em>
386 to zero (the start of the buffer).
388 <p><code class=
"function">lwres_buffer_forward()
</code>
389 increases the consumed region of buffer
390 <em class=
"parameter"><code>*b
</code></em>
392 <em class=
"parameter"><code>n
</code></em>
393 bytes, checking for overflow.
395 <code class=
"function">lwres_buffer_back()
</code>
397 <em class=
"parameter"><code>b
</code></em>'s
399 <em class=
"parameter"><code>n
</code></em>
400 bytes and checks for underflow.
402 <p><code class=
"function">lwres_buffer_getuint8()
</code>
403 reads an unsigned
8-bit integer from
404 <em class=
"parameter"><code>*b
</code></em>
406 <code class=
"function">lwres_buffer_putuint8()
</code>
407 writes the unsigned
8-bit integer
408 <em class=
"parameter"><code>val
</code></em>
410 <em class=
"parameter"><code>*b
</code></em>.
412 <p><code class=
"function">lwres_buffer_getuint16()
</code>
414 <code class=
"function">lwres_buffer_getuint32()
</code>
416 <code class=
"function">lwres_buffer_putuint8()
</code>
417 except that they respectively read an unsigned
16-bit or
32-bit integer
418 in network byte order from
419 <em class=
"parameter"><code>b
</code></em>.
421 <code class=
"function">lwres_buffer_putuint16()
</code>
423 <code class=
"function">lwres_buffer_putuint32()
</code>
424 writes the unsigned
16-bit or
32-bit integer
425 <em class=
"parameter"><code>val
</code></em>
427 <em class=
"parameter"><code>b
</code></em>,
428 in network byte order.
431 Arbitrary amounts of data are read or written from a lightweight
433 <code class=
"function">lwres_buffer_getmem()
</code>
435 <code class=
"function">lwres_buffer_putmem()
</code>
437 <code class=
"function">lwres_buffer_putmem()
</code>
439 <em class=
"parameter"><code>length
</code></em>
441 <em class=
"parameter"><code>base
</code></em>
443 <em class=
"parameter"><code>b
</code></em>.
445 <code class=
"function">lwres_buffer_getmem()
</code>
447 <em class=
"parameter"><code>length
</code></em>
449 <em class=
"parameter"><code>b
</code></em>
451 <em class=
"parameter"><code>base
</code></em>.