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 uint8_t lwres_buffer_getuint8(lwres_buffer_t *b);
34
35 void lwres_buffer_putuint8(lwres_buffer_t *b, uint8_t val);
36
37 uint16_t lwres_buffer_getuint16(lwres_buffer_t *b);
38
39 void lwres_buffer_putuint16(lwres_buffer_t *b, uint16_t val);
40
41 uint32_t lwres_buffer_getuint32(lwres_buffer_t *b);
42
43 void lwres_buffer_putuint32(lwres_buffer_t *b, 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 a == base of buffer.
86 b == current pointer. Can be anywhere between a and d.
87 c == active pointer. Meaningful between b and d.
88 d == used pointer.
89 e == length of buffer.
90
91 a-e == entire length of buffer.
92 a-d == used region.
93 a-b == consumed region.
94 b-d == remaining region.
95 b-c == optional active region.
96
97 lwres_buffer_init() initializes the lwres_buffer_t *b and associates it
98 with the memory region of size length bytes starting at location base.
99
100 lwres_buffer_invalidate() marks the buffer *b as invalid. Invalidating
101 a buffer after use is not required, but makes it possible to catch its
102 possible accidental use.
103
104 The functions lwres_buffer_add() and lwres_buffer_subtract()
105 respectively increase and decrease the used space in buffer *b by n
106 bytes. lwres_buffer_add() checks for buffer overflow and
107 lwres_buffer_subtract() checks for underflow. These functions do not
108 allocate or deallocate memory. They just change the value of used.
109
110 A buffer is re-initialised by lwres_buffer_clear(). The function sets
111 used, current and active to zero.
112
113 lwres_buffer_first makes the consumed region of buffer *p empty by
114 setting current to zero (the start of the buffer).
115
116 lwres_buffer_forward() increases the consumed region of buffer *b by n
117 bytes, checking for overflow. Similarly, lwres_buffer_back() decreases
118 buffer b's consumed region by n bytes and checks for underflow.
119
120 lwres_buffer_getuint8() reads an unsigned 8-bit integer from *b and
121 returns it. lwres_buffer_putuint8() writes the unsigned 8-bit integer
122 val to buffer *b.
123
124 lwres_buffer_getuint16() and lwres_buffer_getuint32() are identical to
125 lwres_buffer_putuint8() except that they respectively read an unsigned
126 16-bit or 32-bit integer in network byte order from b. Similarly,
127 lwres_buffer_putuint16() and lwres_buffer_putuint32() writes the
128 unsigned 16-bit or 32-bit integer val to buffer b, in network byte
129 order.
130
131 Arbitrary amounts of data are read or written from a lightweight
132 resolver buffer with lwres_buffer_getmem() and lwres_buffer_putmem()
133 respectively. lwres_buffer_putmem() copies length bytes of memory at
134 base to b. Conversely, lwres_buffer_getmem() copies length bytes of
135 memory from b to base.
136
138 Internet Systems Consortium, Inc.
139
141 Copyright © 2000, 2001, 2004, 2005, 2007, 2014-2016, 2018-2021 Internet
142 Systems Consortium, Inc. ("ISC")
143
144
145
146ISC 2007-06-18 LWRES_BUFFER(3)