ISC DHCP  4.3.3
A reference DHCPv4 and DHCPv6 implementation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1996-2003 by Internet Software Consortium
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
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);
72 isc_result_t omapi_connection_flush (omapi_object_t *);
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 
struct _omapi_buffer omapi_buffer_t
isc_result_t omapi_connection_copyin(omapi_object_t *, const unsigned char *, unsigned)
Definition: buffer.c:266
struct _omapi_buffer * next
Definition: buffer.h:50
isc_result_t omapi_connection_put_uint32(omapi_object_t *, u_int32_t)
Definition: buffer.c:587
isc_result_t omapi_connection_require(omapi_object_t *, unsigned)
Definition: connection.c:559
u_int32_t refcnt
Definition: buffer.h:51
u_int16_t tail
Definition: buffer.h:52
u_int16_t head
Definition: buffer.h:52
isc_result_t omapi_connection_get_uint32(omapi_object_t *, u_int32_t *)
Definition: buffer.c:572
isc_result_t omapi_connection_flush(omapi_object_t *)
isc_result_t omapi_connection_put_uint16(omapi_object_t *, u_int32_t)
Definition: buffer.c:613
isc_result_t omapi_connection_copyout(unsigned char *, omapi_object_t *, unsigned)
Definition: buffer.c:360
isc_result_t omapi_connection_get_uint16(omapi_object_t *, u_int16_t *)
Definition: buffer.c:598
#define OMAPI_BUF_SIZE
Definition: buffer.h:48
char buf[OMAPI_BUF_SIZE]
Definition: buffer.h:53