2
.\" Copyright (C) 2000, 2001 Internet Software Consortium.
4
.\" Permission to use, copy, modify, and distribute this software for any
5
.\" purpose with or without fee is hereby granted, provided that the above
6
.\" copyright notice and this permission notice appear in all copies.
8
.\" THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9
.\" DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11
.\" INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12
.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13
.\" FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14
.\" NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15
.\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
.TH "LWRES_BUFFER" "3" "Jun 30, 2000" "BIND9" ""
19
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
21
\fB#include <lwres/lwbuffer.h>
25
lwres_buffer_init(lwres_buffer_t *b, void *base, unsigned int length);
30
lwres_buffer_invalidate(lwres_buffer_t *b);
35
lwres_buffer_add(lwres_buffer_t *b, unsigned int n);
40
lwres_buffer_subtract(lwres_buffer_t *b, unsigned int n);
45
lwres_buffer_clear(lwres_buffer_t *b);
50
lwres_buffer_first(lwres_buffer_t *b);
55
lwres_buffer_forward(lwres_buffer_t *b, unsigned int n);
60
lwres_buffer_back(lwres_buffer_t *b, unsigned int n);
65
lwres_buffer_getuint8(lwres_buffer_t *b);
70
lwres_buffer_putuint8(lwres_buffer_t *b, lwres_uint8_t val);
75
lwres_buffer_getuint16(lwres_buffer_t *b);
80
lwres_buffer_putuint16(lwres_buffer_t *b, lwres_uint16_t val);
85
lwres_buffer_getuint32(lwres_buffer_t *b);
90
lwres_buffer_putuint32(lwres_buffer_t *b, lwres_uint32_t val);
95
lwres_buffer_putmem(lwres_buffer_t *b, const unsigned char *base, unsigned int length);
100
lwres_buffer_getmem(lwres_buffer_t *b, unsigned char *base, unsigned int length);
104
These functions provide bounds checked access to a region of memory
105
where data is being read or written.
106
They are based on, and similar to, the
108
functions in the ISC library.
110
A buffer is a region of memory, together with a set of related
112
The \fBused region\fR and the
113
\fBavailable\fR region are disjoint, and
114
their union is the buffer's region.
115
The used region extends from the beginning of the buffer region to the
117
The available region extends from one byte greater than the last used
118
byte to the end of the buffer's region.
119
The size of the used region can be changed using various
121
Initially, the used region is empty.
123
The used region is further subdivided into two disjoint regions: the
124
\fBconsumed region\fR and the \fBremaining region\fR.
125
The union of these two regions is the used region.
126
The consumed region extends from the beginning of the used region to
127
the byte before the \fBcurrent\fR offset (if any).
128
The \fBremaining\fR region the current pointer to the end of the used
130
The size of the consumed region can be changed using various
132
Initially, the consumed region is empty.
134
The \fBactive region\fR is an (optional) subregion of the remaining
136
It extends from the current offset to an offset in the
138
Initially, the active region is empty.
139
If the current offset advances beyond the chosen offset,
140
the active region will also be empty.
145
/------------entire length---------------\\\\
146
/----- used region -----\\\\/-- available --\\\\
147
+----------------------------------------+
148
| consumed | remaining | |
149
+----------------------------------------+
153
b == current pointer. Can be anywhere between a and d.
154
c == active pointer. Meaningful between b and d.
156
e == length of buffer.
158
a-e == entire length of buffer.
160
a-b == consumed region.
161
b-d == remaining region.
162
b-c == optional active region.
166
\fBlwres_buffer_init()\fR
170
and assocates it with the memory region of size
172
bytes starting at location
175
\fBlwres_buffer_invalidate()\fR
178
as invalid. Invalidating a buffer after use is not required,
179
but makes it possible to catch its possible accidental use.
182
\fBlwres_buffer_add()\fR
184
\fBlwres_buffer_subtract()\fR
185
respectively increase and decrease the used space in
191
\fBlwres_buffer_add()\fR
192
checks for buffer overflow and
193
\fBlwres_buffer_subtract()\fR
194
checks for underflow.
195
These functions do not allocate or deallocate memory.
196
They just change the value of
199
A buffer is re-initialised by
200
\fBlwres_buffer_clear()\fR.
208
\fBlwres_buffer_first\fR
209
makes the consumed region of buffer
213
to zero (the start of the buffer).
215
\fBlwres_buffer_forward()\fR
216
increases the consumed region of buffer
220
bytes, checking for overflow.
222
\fBlwres_buffer_back()\fR
227
bytes and checks for underflow.
229
\fBlwres_buffer_getuint8()\fR
230
reads an unsigned 8-bit integer from
233
\fBlwres_buffer_putuint8()\fR
234
writes the unsigned 8-bit integer
239
\fBlwres_buffer_getuint16()\fR
241
\fBlwres_buffer_getuint32()\fR
243
\fBlwres_buffer_putuint8()\fR
244
except that they respectively read an unsigned 16-bit or 32-bit integer
245
in network byte order from
248
\fBlwres_buffer_putuint16()\fR
250
\fBlwres_buffer_putuint32()\fR
251
writes the unsigned 16-bit or 32-bit integer
255
in network byte order.
257
Arbitrary amounts of data are read or written from a lightweight
259
\fBlwres_buffer_getmem()\fR
261
\fBlwres_buffer_putmem()\fR
263
\fBlwres_buffer_putmem()\fR
271
\fBlwres_buffer_getmem()\fR