summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Walton <dwalton@cumulusnetworks.com>2015-10-21 06:56:44 -0700
committerDonald Sharp <sharpd@cumulusnetworks.com>2015-12-08 14:11:14 -0500
commitc8af680df5beb613fd50c265773a6beb0f1768c9 (patch)
treee46da907fe4b493085d8e4bcb51d775cc32ef05b /lib
parent363c903435b154e989f0544d12d4ac8d50174c0b (diff)
downloadquagga-c8af680df5beb613fd50c265773a6beb0f1768c9.tar.bz2
quagga-c8af680df5beb613fd50c265773a6beb0f1768c9.tar.xz
lib: Add zlog_hexdump() for debugging
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com> Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com> Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/log.c42
-rw-r--r--lib/log.h2
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/log.c b/lib/log.c
index f02e4c73..10a771e1 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -1001,3 +1001,45 @@ proto_redistnum(int afi, const char *s)
}
return -1;
}
+
+void
+zlog_hexdump (void *mem, unsigned int len) {
+ unsigned long i = 0;
+ unsigned int j = 0;
+ unsigned int columns = 8;
+ char buf[(len * 4) + ((len/4) * 20) + 30];
+ char *s = buf;
+
+ for (i = 0; i < len + ((len % columns) ? (columns - len % columns) : 0); i++)
+ {
+ /* print offset */
+ if (i % columns == 0)
+ s += sprintf(s, "0x%016lx: ", (unsigned long)mem + i);
+
+ /* print hex data */
+ if (i < len)
+ s += sprintf(s, "%02x ", 0xFF & ((char*)mem)[i]);
+
+ /* end of block, just aligning for ASCII dump */
+ else
+ s += sprintf(s, " ");
+
+ /* print ASCII dump */
+ if (i % columns == (columns - 1))
+ {
+ for (j = i - (columns - 1); j <= i; j++)
+ {
+ if (j >= len) /* end of block, not really printing */
+ s += sprintf(s, " ");
+
+ else if(isprint(((char*)mem)[j])) /* printable char */
+ s += sprintf(s, "%c", 0xFF & ((char*)mem)[j]);
+
+ else /* other char */
+ s += sprintf(s, ".");
+ }
+ s += sprintf(s, "\n");
+ }
+ }
+ zlog_debug("\n%s", buf);
+}
diff --git a/lib/log.h b/lib/log.h
index 77cd53bc..514884cc 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -189,6 +189,8 @@ extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
char *buf, size_t buflen);
+extern void zlog_hexdump(void *mem, unsigned int len);
+
/* structure useful for avoiding repeated rendering of the same timestamp */
struct timestamp_control {
size_t len; /* length of rendered timestamp */