From 0d9b7eeb90fa4fc5978830987555ad12610fbdbf Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 23 Jan 2015 00:17:26 +0100 Subject: Add hexdump support to fastd logging functions --- src/log.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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': -- cgit v1.2.3