summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-01-23 00:17:26 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-01-23 00:17:26 +0100
commit0d9b7eeb90fa4fc5978830987555ad12610fbdbf (patch)
treef99cce11cdcb39151630127abeafddaaaf5230d8
parentfce215716851606f7578a73f34eecd7bcb420d2a (diff)
downloadfastd-0d9b7eeb90fa4fc5978830987555ad12610fbdbf.tar
fastd-0d9b7eeb90fa4fc5978830987555ad12610fbdbf.zip
Add hexdump support to fastd logging functions
-rw-r--r--src/log.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
index a54bc29..7d1538a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -107,6 +107,15 @@ static size_t snprint_peer_str(char *buffer, size_t size, const fastd_peer_t *pe
return snprintf_safe(buffer, size, "(null)");
}
+/** Add a hexdump to a string buffer */
+static size_t snprint_hexdump(char *buffer, size_t size, const uint8_t *d, size_t len) {
+ size_t n = 0, i;
+ for (i = 0; i < len && n < size; i++)
+ n += snprintf_safe(buffer+n, size-n, "%02x", d[i]);
+
+ return n;
+}
+
/** vsnprintf-like function using different conversion specifiers */
static int fastd_vsnprintf(char *buffer, size_t size, const char *format, va_list ap) {
char *buffer_start = buffer;
@@ -171,6 +180,11 @@ static int fastd_vsnprintf(char *buffer, size_t size, const char *format, va_lis
buffer += snprint_peer_str(buffer, buffer_end-buffer, va_arg(ap, const fastd_peer_t *));
break;
+ case 'H':
+ p = va_arg(ap, const uint8_t *);
+ buffer += snprint_hexdump(buffer, buffer_end-buffer, p, va_arg(ap, size_t));
+ break;
+
case 'I':
case 'B':
case 'L':