diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-23 00:17:26 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-23 00:17:26 +0100 |
commit | 0d9b7eeb90fa4fc5978830987555ad12610fbdbf (patch) | |
tree | f99cce11cdcb39151630127abeafddaaaf5230d8 /src | |
parent | fce215716851606f7578a73f34eecd7bcb420d2a (diff) | |
download | fastd-0d9b7eeb90fa4fc5978830987555ad12610fbdbf.tar fastd-0d9b7eeb90fa4fc5978830987555ad12610fbdbf.zip |
Add hexdump support to fastd logging functions
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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': |