1LWRES_BUFFER(3) BIND9 LWRES_BUFFER(3)
2
3
4
6 lwres_buffer_init, lwres_buffer_invalidate, lwres_buffer_add,
7 lwres_buffer_subtract, lwres_buffer_clear, lwres_buffer_first,
8 lwres_buffer_forward, lwres_buffer_back, lwres_buffer_getuint8,
9 lwres_buffer_putuint8, lwres_buffer_getuint16, lwres_buffer_putuint16,
10 lwres_buffer_getuint32, lwres_buffer_putuint32, lwres_buffer_putmem,
11 lwres_buffer_getmem - lightweight resolver buffer management
12
14 #include <lwres/lwbuffer.h>
15
16 void lwres_buffer_init(lwres_buffer_t *b, void *base,
17 unsigned int length);
18
19 void lwres_buffer_invalidate(lwres_buffer_t *b);
20
21 void lwres_buffer_add(lwres_buffer_t *b, unsigned int n);
22
23 void lwres_buffer_subtract(lwres_buffer_t *b, unsigned int n);
24
25 void lwres_buffer_clear(lwres_buffer_t *b);
26
27 void lwres_buffer_first(lwres_buffer_t *b);
28
29 void lwres_buffer_forward(lwres_buffer_t *b, unsigned int n);
30
31 void lwres_buffer_back(lwres_buffer_t *b, unsigned int n);
32
33 lwres_uint8_t lwres_buffer_getuint8(lwres_buffer_t *b);
34
35 void lwres_buffer_putuint8(lwres_buffer_t *b, lwres_uint8_t val);
36
37 lwres_uint16_t lwres_buffer_getuint16(lwres_buffer_t *b);
38
39 void lwres_buffer_putuint16(lwres_buffer_t *b, lwres_uint16_t val);
40
41 lwres_uint32_t lwres_buffer_getuint32(lwres_buffer_t *b);
42
43 void lwres_buffer_putuint32(lwres_buffer_t *b, lwres_uint32_t val);
44
45 void lwres_buffer_putmem(lwres_buffer_t *b, const unsigned char *base,
46 unsigned int length);
47
48 void lwres_buffer_getmem(lwres_buffer_t *b, unsigned char *base,
49 unsigned int length);
50
52 These functions provide bounds checked access to a region of memory
53 where data is being read or written. They are based on, and similar to,
54 the isc_buffer_ functions in the ISC library.
55
56 A buffer is a region of memory, together with a set of related
57 subregions. The used region and the available region are disjoint, and
58 their union is the buffer's region. The used region extends from the
59 beginning of the buffer region to the last used byte. The available
60 region extends from one byte greater than the last used byte to the end
61 of the buffer's region. The size of the used region can be changed
62 using various buffer commands. Initially, the used region is empty.
63
64 The used region is further subdivided into two disjoint regions: the
65 consumed region and the remaining region. The union of these two
66 regions is the used region. The consumed region extends from the
67 beginning of the used region to the byte before the current offset (if
68 any). The remaining region the current pointer to the end of the used
69 region. The size of the consumed region can be changed using various
70 buffer commands. Initially, the consumed region is empty.
71
72 The active region is an (optional) subregion of the remaining region.
73 It extends from the current offset to an offset in the remaining
74 region. Initially, the active region is empty. If the current offset
75 advances beyond the chosen offset, the active region will also be
76 empty.
77
78 /------------entire length---------------\\
79 /----- used region -----\\/-- available --\\
80 +----------------------------------------+
81 | consumed | remaining | |
82 +----------------------------------------+
83 a b c d e
84
85
86 a == base of buffer.
87 b == current pointer. Can be anywhere between a and d.
88 c == active pointer. Meaningful between b and d.
89 d == used pointer.
90 e == length of buffer.
91
92
93 a-e == entire length of buffer.
94 a-d == used region.
95 a-b == consumed region.
96 b-d == remaining region.
97 b-c == optional active region.
98
99
100 lwres_buffer_init() initializes the lwres_buffer_t *b and assocates it
101 with the memory region of size length bytes starting at location base.
102
103 lwres_buffer_invalidate() marks the buffer *b as invalid. Invalidating
104 a buffer after use is not required, but makes it possible to catch its
105 possible accidental use.
106
107 The functions lwres_buffer_add() and lwres_buffer_subtract()
108 respectively increase and decrease the used space in buffer *b by n
109 bytes. lwres_buffer_add() checks for buffer overflow and
110 lwres_buffer_subtract() checks for underflow. These functions do not
111 allocate or deallocate memory. They just change the value of used.
112
113 A buffer is re-initialised by lwres_buffer_clear(). The function sets
114 used, current and active to zero.
115
116 lwres_buffer_first makes the consumed region of buffer *p empty by
117 setting current to zero (the start of the buffer).
118
119 lwres_buffer_forward() increases the consumed region of buffer *b by n
120 bytes, checking for overflow. Similarly, lwres_buffer_back() decreases
121 buffer b's consumed region by n bytes and checks for underflow.
122
123 lwres_buffer_getuint8() reads an unsigned 8-bit integer from *b and
124 returns it. lwres_buffer_putuint8() writes the unsigned 8-bit integer
125 val to buffer *b.
126
127 lwres_buffer_getuint16() and lwres_buffer_getuint32() are identical to
128 lwres_buffer_putuint8() except that they respectively read an unsigned
129 16-bit or 32-bit integer in network byte order from b. Similarly,
130 lwres_buffer_putuint16() and lwres_buffer_putuint32() writes the
131 unsigned 16-bit or 32-bit integer val to buffer b, in network byte
132 order.
133
134 Arbitrary amounts of data are read or written from a lightweight
135 resolver buffer with lwres_buffer_getmem() and lwres_buffer_putmem()
136 respectively. lwres_buffer_putmem() copies length bytes of memory at
137 base to b. Conversely, lwres_buffer_getmem() copies length bytes of
138 memory from b to base.
139
141 Copyright © 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
142 Copyright © 2000, 2001 Internet Software Consortium.
143
144
145
146BIND9 Jun 30, 2000 LWRES_BUFFER(3)