Go to the documentation of this file.
30 #define MAX_LIMIT 10485760
37 "buffer with size greater than API limit - %d",
43 size_t total_size = size +
sizeof(
MemBuffer);
61 if (((*buffer)->size + expand_by) >
MAX_LIMIT) {
63 "buffer with size greater than API limit - %d",
69 if (expand_by % 4096 != 0) {
70 expand_by = expand_by - (expand_by % 4096) + 4096;
73 size_t total_size = (*buffer)->size +
sizeof(
MemBuffer) + expand_by;
80 (*buffer)->
size += expand_by;
82 SCLogDebug(
"expanded buffer by %u, size is now %u", expand_by, (*buffer)->size);
93 for (uint32_t i = 0; i < buffer->
offset; i++) {
94 if (isprint(buffer->
buffer[i]))
95 fprintf(fp,
"%c", buffer->
buffer[i]);
97 fprintf(fp,
"|%02X|", buffer->
buffer[i]);
111 fprintf(fp,
" %02X", b->
buffer[i]);
118 if (raw_len >=
dst->size -
dst->offset) {
119 SCLogDebug(
"Truncating data write since it exceeded buffer limit of %" PRIu32,
dst->size);
120 write_len =
dst->size -
dst->offset - 1;
124 memcpy(
dst->buffer +
dst->offset, raw, write_len);
125 dst->offset += write_len;
126 dst->buffer[
dst->offset] =
'\0';
132 uint32_t available =
dst->size -
dst->offset;
133 uint32_t max_string_size =
MIN(available, 2048);
135 char string[max_string_size];
137 int written = vsnprintf(
string,
sizeof(
string), fmt, ap);
141 }
else if ((uint32_t)written > max_string_size) {
142 SCLogDebug(
"Truncating data write since it exceeded buffer "
146 size_t string_size = strlen(
string);
147 memcpy(
dst->buffer +
dst->offset,
string, string_size);
148 dst->offset += string_size;
149 dst->buffer[
dst->offset] =
'\0';
int MemBufferExpand(MemBuffer **buffer, uint32_t expand_by)
expand membuffer by size of 'expand_by'
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SCRealloc(ptr, sz)
void MemBufferFree(MemBuffer *buffer)
void MemBufferPrintToFP(MemBuffer *buffer, FILE *fp)
Write a buffer to the file pointer.
struct MemBuffer_ MemBuffer
void MemBufferPrintToFPAsHex(MemBuffer *b, FILE *fp)
Write a buffer in hex format.
thread_local SCError sc_errno
uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len)
Write a raw buffer to the MemBuffer dst.
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
#define MEMBUFFER_BUFFER(mem_buffer)
Get the MemBuffers underlying buffer.
size_t MemBufferPrintToFPAsString(MemBuffer *b, FILE *fp)
Write a buffer to the file pointer as a printable char string.
#define MEMBUFFER_OFFSET(mem_buffer)
Get the MemBuffers current offset.
MemBuffer * MemBufferCreateNew(uint32_t size)