ISC DHCP  4.4.2b1
A reference DHCPv4 and DHCPv6 implementation
buffer.h
Go to the documentation of this file.
1 /* buffer.h
2 
3  Definitions for the object management API protocol buffering... */
4 
5 /*
6  * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1996-2003 by Internet Software Consortium
8  *
9  * This Source Code Form is subject to the terms of the Mozilla Public
10  * License, v. 2.0. If a copy of the MPL was not distributed with this
11  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  * Internet Systems Consortium, Inc.
22  * 950 Charter Street
23  * Redwood City, CA 94063
24  * <info@isc.org>
25  * https://www.isc.org/
26  *
27  */
28 
29 /* OMAPI buffers are ring buffers, which means that the beginning of the
30  buffer and the end of the buffer chase each other around. As long as
31  the tail never catches up to the head, there's room in the buffer for
32  data.
33 
34  - If the tail and the head are equal, the buffer is empty.
35 
36  - If the tail is less than the head, the contents of the buffer
37  are the bytes from the head to the end of buffer, and in addition,
38  the bytes between the beginning of the buffer and the tail, not
39  including the byte addressed by the tail.
40 
41  - If the tail is greater than the head, then the buffer contains
42  valid bytes starting with the byte addressed by the head, and
43  ending with the byte before the byte addressed by the tail.
44 
45  There will always be at least one byte of waste, because the tail can't
46  increase so that it's equal to the head (that would represent an empty
47  buffer. */
48 #define OMAPI_BUF_SIZE 4048
49 typedef struct _omapi_buffer {
50  struct _omapi_buffer *next; /* Buffers can be chained. */
51  u_int32_t refcnt; /* Buffers are reference counted. */
52  u_int16_t head, tail; /* Buffers are organized in a ring. */
53  char buf [OMAPI_BUF_SIZE]; /* The actual buffer is included in
54  the buffer data structure. */
56 
57 #define BUFFER_BYTES_FREE(x) \
58  ((x) -> tail > (x) -> head \
59  ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \
60  : (x) -> head - (x) -> tail)
61 
62 #define BYTES_IN_BUFFER(x) \
63  ((x) -> tail > (x) -> head \
64  ? (x) -> tail - (x) -> head - 1 \
65  : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1)
66 
67 isc_result_t omapi_connection_require (omapi_object_t *, unsigned);
68 isc_result_t omapi_connection_copyout (unsigned char *,
69  omapi_object_t *, unsigned);
71  const unsigned char *, unsigned);
73 isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *);
74 isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t);
75 isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *);
76 isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t);
77 
omapi_connection_require
isc_result_t omapi_connection_require(omapi_object_t *, unsigned)
Definition: connection.c:560
omapi_connection_copyout
isc_result_t omapi_connection_copyout(unsigned char *, omapi_object_t *, unsigned)
Definition: buffer.c:359
_omapi_buffer::head
u_int16_t head
Definition: buffer.h:52
OMAPI_BUF_SIZE
#define OMAPI_BUF_SIZE
Definition: buffer.h:48
omapi_connection_get_uint32
isc_result_t omapi_connection_get_uint32(omapi_object_t *, u_int32_t *)
Definition: buffer.c:580
_omapi_buffer::buf
char buf[OMAPI_BUF_SIZE]
Definition: buffer.h:53
omapi_connection_put_uint16
isc_result_t omapi_connection_put_uint16(omapi_object_t *, u_int32_t)
Definition: buffer.c:621
omapi_buffer_t
struct _omapi_buffer omapi_buffer_t
omapi_connection_get_uint16
isc_result_t omapi_connection_get_uint16(omapi_object_t *, u_int16_t *)
Definition: buffer.c:606
_omapi_buffer::next
struct _omapi_buffer * next
Definition: buffer.h:50
omapi_connection_put_uint32
isc_result_t omapi_connection_put_uint32(omapi_object_t *, u_int32_t)
Definition: buffer.c:595
__omapi_object
Definition: omapip.h:127
_omapi_buffer::refcnt
u_int32_t refcnt
Definition: buffer.h:51
omapi_connection_flush
isc_result_t omapi_connection_flush(omapi_object_t *)
_omapi_buffer
Definition: buffer.h:49
omapi_connection_copyin
isc_result_t omapi_connection_copyin(omapi_object_t *, const unsigned char *, unsigned)
Definition: buffer.c:265
_omapi_buffer::tail
u_int16_t tail
Definition: buffer.h:52