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",
68 size_t total_size = (*buffer)->size +
sizeof(
MemBuffer) + expand_by;
75 (*buffer)->
size += expand_by;
77 SCLogDebug(
"expanded buffer by %u, size is now %u", expand_by, (*buffer)->size);
88 for (uint32_t i = 0; i < buffer->
offset; i++) {
89 if (isprint(buffer->
buffer[i]))
90 fprintf(fp,
"%c", buffer->
buffer[i]);
92 fprintf(fp,
"|%02X|", buffer->
buffer[i]);
106 fprintf(fp,
" %02X", b->
buffer[i]);
113 if (raw_len >=
dst->size -
dst->offset) {
114 SCLogDebug(
"Truncating data write since it exceeded buffer limit of %" PRIu32,
dst->size);
115 write_len =
dst->size -
dst->offset - 1;
119 memcpy(
dst->buffer +
dst->offset, raw, write_len);
120 dst->offset += write_len;
121 dst->buffer[
dst->offset] =
'\0';
127 uint32_t available =
dst->size -
dst->offset;
128 uint32_t max_string_size =
MIN(available, 2048);
130 char string[max_string_size];
132 int written = vsnprintf(
string,
sizeof(
string), fmt, ap);
136 }
else if ((uint32_t)written > max_string_size) {
137 SCLogDebug(
"Truncating data write since it exceeded buffer "
141 size_t string_size = strlen(
string);
142 memcpy(
dst->buffer +
dst->offset,
string, string_size);
143 dst->offset += string_size;
144 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)