From c4b9283bbb69e7754555ce7dc21c769ca205dd08 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 2 Nov 2007 11:33:53 +0100 Subject: r25799: Add dump_data_skip_zeros() which omits 16 zero bytes in a row (if not at the beginning or the end of a blob). Usefull when inspecting protocols that exchange huge mostly empty blobs. Guenther (This used to be commit c96047d022555678dabe08c0de94f0913bb4d047) --- source4/lib/util/util.c | 72 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 9 deletions(-) (limited to 'source4/lib/util/util.c') diff --git a/source4/lib/util/util.c b/source4/lib/util/util.c index 2a2813f9af..ac9ae779a0 100644 --- a/source4/lib/util/util.c +++ b/source4/lib/util/util.c @@ -393,24 +393,55 @@ static void print_asc(int level, const uint8_t *buf,int len) * * The data is only written if the log level is at least level. */ -_PUBLIC_ void dump_data(int level, const uint8_t *buf,int len) +static void _dump_data(int level, const uint8_t *buf, int len, + bool omit_zero_bytes) { int i=0; + const uint8_t empty[16]; + bool skipped = false; + if (len<=0) return; if (!DEBUGLVL(level)) return; - - DEBUGADD(level,("[%03X] ",i)); + + memset(&empty, '\0', 16); + for (i=0;i 0) && + (len > i+16) && + (memcmp(&buf[i], &empty, 16) == 0)) + { + i +=16; + continue; + } + + if (i i+16) && + (memcmp(&buf[i], &empty, 16) == 0)) { + if (!skipped) { + DEBUGADD(level,("skipping zero buffer bytes\n")); + skipped = true; + } + } } } + if (i%16) { int n; n = 16 - (i%16); @@ -420,11 +451,34 @@ _PUBLIC_ void dump_data(int level, const uint8_t *buf,int len) n = MIN(8,i%16); print_asc(level,&buf[i-(i%16)],n); DEBUGADD(level,( " " )); n = (i%16) - n; - if (n>0) print_asc(level,&buf[i-n],n); - DEBUGADD(level,("\n")); - } + if (n>0) print_asc(level,&buf[i-n],n); + DEBUGADD(level,("\n")); + } + } +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + */ +_PUBLIC_ void dump_data(int level, const uint8_t *buf, int len) +{ + return _dump_data(level, buf, len, false); +} + +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + * 16 zero bytes in a row are ommited + */ +_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len) +{ + return _dump_data(level, buf, len, true); +} + + /** malloc that aborts with smb_panic on fail or zero size. **/ -- cgit