Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1
9#ifndef __W_BUFFER_H__
10#define __W_BUFFER_H__
11
12#include <inttypes.h>
13#include <stddef.h>
14#include "ws_symbol_export.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20#define SOME_FUNCTIONS_ARE_INLINE
21
22#define DEFAULT_INIT_BUFFER_SIZE_2048 (2 * 1024) /* Everyone still uses 1500 byte frames, right? */
23
30typedef struct Buffer {
31 uint8_t *data;
32 size_t allocated;
33 size_t start;
34 size_t first_free;
36
45WS_DLL_PUBLIC
46void ws_buffer_init(Buffer* buffer, size_t space);
47
55WS_DLL_PUBLIC
57
66WS_DLL_PUBLIC
67void ws_buffer_assure_space(Buffer* buffer, size_t space);
68
79WS_DLL_PUBLIC
80void ws_buffer_append(Buffer* buffer, const uint8_t *from, size_t bytes);
81
91WS_DLL_PUBLIC
92void ws_buffer_remove_start(Buffer* buffer, size_t bytes);
93
100WS_DLL_PUBLIC
101void ws_buffer_cleanup(void);
102
103#ifdef SOME_FUNCTIONS_ARE_INLINE
104/* Or inlines */
105static inline void
106ws_buffer_clean(Buffer *buffer)
107{
108 buffer->start = 0;
109 buffer->first_free = 0;
110}
111
112static inline void
113ws_buffer_increase_length(Buffer* buffer, size_t bytes)
114{
115 buffer->first_free += bytes;
116}
117
118static inline size_t
119ws_buffer_length(const Buffer* buffer)
120{
121 return buffer->first_free - buffer->start;
122}
123
124static inline uint8_t *
125ws_buffer_start_ptr(const Buffer* buffer)
126{
127 return buffer->data + buffer->start;
128}
129
130static inline uint8_t *
131ws_buffer_end_ptr(const Buffer* buffer)
132{
133 return buffer->data + buffer->first_free;
134}
135
136static inline void
137ws_buffer_append_buffer(Buffer* buffer, const Buffer* src_buffer)
138{
139 ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
140}
141#else
142
151WS_DLL_PUBLIC
152void ws_buffer_clean(Buffer* buffer);
153
163WS_DLL_PUBLIC
164void ws_buffer_increase_length(Buffer* buffer, size_t bytes);
165
174WS_DLL_PUBLIC
175size_t ws_buffer_length(const Buffer* buffer);
176
183WS_DLL_PUBLIC
184uint8_t* ws_buffer_start_ptr(const Buffer* buffer);
185
192WS_DLL_PUBLIC
193uint8_t* ws_buffer_end_ptr(const Buffer* buffer);
194
203WS_DLL_PUBLIC
204void ws_buffer_append_buffer(Buffer* buffer, const Buffer* src_buffer);
205
206#endif
207
208#ifdef __cplusplus
209}
210#endif /* __cplusplus */
211
212#endif
WS_DLL_PUBLIC void ws_buffer_free(Buffer *buffer)
Frees the memory associated with a Buffer.
Definition buffer.c:46
WS_DLL_PUBLIC void ws_buffer_append(Buffer *buffer, const uint8_t *from, size_t bytes)
Appends data to the end of the buffer.
Definition buffer.c:102
WS_DLL_PUBLIC void ws_buffer_assure_space(Buffer *buffer, size_t space)
Ensures the buffer has enough space for additional data.
Definition buffer.c:64
WS_DLL_PUBLIC void ws_buffer_remove_start(Buffer *buffer, size_t bytes)
Removes bytes from the beginning of the buffer.
Definition buffer.c:111
WS_DLL_PUBLIC void ws_buffer_init(Buffer *buffer, size_t space)
Initializes a Buffer with the specified initial capacity.
Definition buffer.c:23
WS_DLL_PUBLIC void ws_buffer_cleanup(void)
Cleans up internal buffer state across all active buffers.
Definition buffer.c:177
A dynamic byte buffer with adjustable start and end positions.
Definition buffer.h:30
uint8_t * data
Definition buffer.h:31
size_t allocated
Definition buffer.h:32
size_t first_free
Definition buffer.h:34
size_t start
Definition buffer.h:33
Definition mcast_stream.h:30