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 */
105
111static inline void
112ws_buffer_clean(Buffer *buffer)
113{
114 buffer->start = 0;
115 buffer->first_free = 0;
116}
117
124static inline void
125ws_buffer_increase_length(Buffer* buffer, size_t bytes)
126{
127 buffer->first_free += bytes;
128}
129
136static inline size_t
137ws_buffer_length(const Buffer* buffer)
138{
139 return buffer->first_free - buffer->start;
140}
141
148static inline uint8_t *
149ws_buffer_start_ptr(const Buffer* buffer)
150{
151 return buffer->data + buffer->start;
152}
153
160static inline uint8_t *
161ws_buffer_end_ptr(const Buffer* buffer)
162{
163 return buffer->data + buffer->first_free;
164}
165
172static inline void
173ws_buffer_append_buffer(Buffer* buffer, const Buffer* src_buffer)
174{
175 ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
176}
177#else
178
187WS_DLL_PUBLIC
188void ws_buffer_clean(Buffer* buffer);
189
199WS_DLL_PUBLIC
200void ws_buffer_increase_length(Buffer* buffer, size_t bytes);
201
210WS_DLL_PUBLIC
211size_t ws_buffer_length(const Buffer* buffer);
212
224WS_DLL_PUBLIC
225uint8_t* ws_buffer_start_ptr(const Buffer* buffer);
226
238WS_DLL_PUBLIC
239uint8_t* ws_buffer_end_ptr(const Buffer* buffer);
240
249WS_DLL_PUBLIC
250void ws_buffer_append_buffer(Buffer* buffer, const Buffer* src_buffer);
251
252#endif
253
254#ifdef __cplusplus
255}
256#endif /* __cplusplus */
257
258#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:179
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