1378N/A<!
DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
1378N/A - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC") 1378N/A - Copyright (C) 2000, 2001 Internet Software Consortium. 1378N/A - Permission to use, copy, modify, and distribute this software for any 1378N/A - purpose with or without fee is hereby granted, provided that the above 1378N/A - copyright notice and this permission notice appear in all copies. 1378N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 1378N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 1378N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 1378N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 1378N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 1378N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 1378N/A - PERFORMANCE OF THIS SOFTWARE. 1378N/A<
refentrytitle>lwres_buffer</
refentrytitle>
5112N/A<
refmiscinfo>BIND9</
refmiscinfo>
1378N/A<
refname>lwres_buffer_init</
refname>
5112N/A<
refname>lwres_buffer_invalidate</
refname>
1378N/A<
refname>lwres_buffer_add</
refname>
3926N/A<
refname>lwres_buffer_subtract</
refname>
3926N/A<
refname>lwres_buffer_clear</
refname>
5112N/A<
refname>lwres_buffer_first</
refname>
1378N/A<
refname>lwres_buffer_forward</
refname>
5680N/A<
refname>lwres_buffer_back</
refname>
5680N/A<
refname>lwres_buffer_getuint8</
refname>
1378N/A<
refname>lwres_buffer_putuint8</
refname>
1378N/A<
refname>lwres_buffer_getuint16</
refname>
1378N/A<
refname>lwres_buffer_putuint16</
refname>
5680N/A<
refname>lwres_buffer_getuint32</
refname>
1378N/A<
refname>lwres_buffer_putuint32</
refname>
1378N/A<
refname>lwres_buffer_putmem</
refname>
1378N/A<
refname>lwres_buffer_getmem</
refname>
1586N/A<
refpurpose>lightweight resolver buffer management</
refpurpose>
3817N/A<
function>lwres_buffer_init</
function></
funcdef>
3817N/A<
paramdef>lwres_buffer_t *b</
paramdef>
3817N/A<
paramdef>void *base</
paramdef>
<
paramdef>unsigned int length</
paramdef>
<
function>lwres_buffer_invalidate</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
function>lwres_buffer_add</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>unsigned int n</
paramdef>
<
function>lwres_buffer_subtract</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>unsigned int n</
paramdef>
<
function>lwres_buffer_clear</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
function>lwres_buffer_first</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
function>lwres_buffer_forward</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>unsigned int n</
paramdef>
<
function>lwres_buffer_back</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>unsigned int n</
paramdef>
<
function>lwres_buffer_getuint8</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
function>lwres_buffer_putuint8</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>lwres_uint8_t val</
paramdef>
<
function>lwres_buffer_getuint16</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
function>lwres_buffer_putuint16</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>lwres_uint16_t val</
paramdef>
<
function>lwres_buffer_getuint32</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
function>lwres_buffer_putuint32</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>lwres_uint32_t val</
paramdef>
<
function>lwres_buffer_putmem</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>const unsigned char *base</
paramdef>
<
paramdef>unsigned int length</
paramdef>
<
function>lwres_buffer_getmem</
function></
funcdef>
<
paramdef>lwres_buffer_t *b</
paramdef>
<
paramdef>unsigned char *base</
paramdef>
<
paramdef>unsigned int length</
paramdef>
<
title>DESCRIPTION</
title>
These functions provide bounds checked access to a region of memory
where data is being read or written.
They are based on, and similar to, the
<
literal>isc_buffer_</
literal>
functions in the ISC library.
A buffer is a region of memory, together with a set of related
The <
emphasis>used region</
emphasis> and the
<
emphasis>available</
emphasis> region are disjoint, and
their union is the buffer's region.
The used region extends from the beginning of the buffer region to the
The available region extends from one byte greater than the last used
byte to the end of the buffer's region.
The size of the used region can be changed using various
Initially, the used region is empty.
The used region is further subdivided into two disjoint regions: the
<
emphasis>consumed region</
emphasis> and the <
emphasis>remaining region</
emphasis>.
The union of these two regions is the used region.
The consumed region extends from the beginning of the used region to
the byte before the <
emphasis>current</
emphasis> offset (if any).
The <
emphasis>remaining</
emphasis> region the current pointer to the end of the used
The size of the consumed region can be changed using various
Initially, the consumed region is empty.
The <
emphasis>active region</
emphasis> is an (optional) subregion of the remaining
It extends from the current offset to an offset in the
Initially, the active region is empty.
If the current offset advances beyond the chosen offset,
the active region will also be empty.
/------------entire length---------------\\
/----- used region -----\\/-- available --\\
+----------------------------------------+
| consumed | remaining | |
+----------------------------------------+
b == current pointer. Can be anywhere between a and d.
c == active pointer. Meaningful between b and d.
a-e == entire length of buffer.
b-c == optional active region.
<
function>lwres_buffer_init()</
function>
<
type>lwres_buffer_t</
type>
<
parameter>*b</
parameter>
and assocates it with the memory region of size
<
parameter>length</
parameter>
bytes starting at location
<
parameter>base.</
parameter>
<
function>lwres_buffer_invalidate()</
function>
<
parameter>*b</
parameter>
as invalid. Invalidating a buffer after use is not required,
but makes it possible to catch its possible accidental use.
<
function>lwres_buffer_add()</
function>
<
function>lwres_buffer_subtract()</
function>
respectively increase and decrease the used space in
<
parameter>*b</
parameter>
<
function>lwres_buffer_add()</
function>
checks for buffer overflow and
<
function>lwres_buffer_subtract()</
function>
These functions do not allocate or deallocate memory.
They just change the value of
<
structfield>used</
structfield>.
A buffer is re-initialised by
<
function>lwres_buffer_clear()</
function>.
<
structfield>used</
structfield> ,
<
structfield>current</
structfield>
<
structfield>active</
structfield>
<
function>lwres_buffer_first</
function>
makes the consumed region of buffer
<
parameter>*p</
parameter>
<
structfield>current</
structfield>
to zero (the start of the buffer).
<
function>lwres_buffer_forward()</
function>
increases the consumed region of buffer
<
parameter>*b</
parameter>
bytes, checking for overflow.
<
function>lwres_buffer_back()</
function>
<
parameter>b</
parameter>'s
bytes and checks for underflow.
<
function>lwres_buffer_getuint8()</
function>
reads an unsigned 8-bit integer from
<
parameter>*b</
parameter>
<
function>lwres_buffer_putuint8()</
function>
writes the unsigned 8-bit integer
<
parameter>val</
parameter>
<
parameter>*b</
parameter>.
<
function>lwres_buffer_getuint16()</
function>
<
function>lwres_buffer_getuint32()</
function>
<
function>lwres_buffer_putuint8()</
function>
except that they respectively read an unsigned 16-bit or 32-bit integer
in network byte order from
<
parameter>b</
parameter>.
<
function>lwres_buffer_putuint16()</
function>
<
function>lwres_buffer_putuint32()</
function>
writes the unsigned 16-bit or 32-bit integer
<
parameter>val</
parameter>
<
parameter>b</
parameter>,
Arbitrary amounts of data are read or written from a lightweight
<
function>lwres_buffer_getmem()</
function>
<
function>lwres_buffer_putmem()</
function>
<
function>lwres_buffer_putmem()</
function>
<
parameter>length</
parameter>
<
parameter>base</
parameter>
<
parameter>b</
parameter>.
<
function>lwres_buffer_getmem()</
function>
<
parameter>length</
parameter>
<
parameter>base</
parameter>.