diff options
author | Martin Szulecki | 2014-07-26 17:32:27 +0200 |
---|---|---|
committer | Martin Szulecki | 2014-07-26 17:32:27 +0200 |
commit | 06a26dbc0c9fc7e96d211481bc6dd2944d7aeb36 (patch) | |
tree | cc4789377ed7b2cb001c26d9dd2bdcea3fa1707f /src | |
parent | aede4d06c49a8446e8011ab569c765a4f4ba32e7 (diff) | |
download | usbmuxd-lograw.tar.gz usbmuxd-lograw.tar.bz2 |
Add usbmuxd_log_buffer helper for easier debugging of binary payloadslograw
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 57 | ||||
-rw-r--r-- | src/log.h | 2 |
2 files changed, 53 insertions, 6 deletions
@@ -61,6 +61,24 @@ static int level_to_syslog_level(int level) return result; } +static void usbmuxd_vlog_raw(enum loglevel level, const char *fmt, va_list ap) +{ + if (log_syslog) { + vsyslog(level_to_syslog_level(level), fmt, ap); + } else { + vfprintf(stderr, fmt, ap); + } +} + +static void usbmuxd_log_raw(enum loglevel level, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + usbmuxd_vlog_raw(level, fmt, ap); + va_end(ap); +} + void usbmuxd_log(enum loglevel level, const char *fmt, ...) { va_list ap; @@ -84,12 +102,41 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...) } va_start(ap, fmt); - if (log_syslog) { - vsyslog(level_to_syslog_level(level), fs, ap); - } else { - vfprintf(stderr, fs, ap); - } + usbmuxd_vlog_raw(level, fs, ap); va_end(ap); free(fs); } + +void usbmuxd_log_buffer(enum loglevel level, const unsigned char *data, const size_t length) +{ + if(level > log_level) + return; + + size_t i; + int j; + unsigned char c; + + for (i = 0; i < length; i += 16) { + usbmuxd_log_raw(level, "%04x: ", i); + for (j = 0; j < 16; j++) { + if (i + j >= length) { + usbmuxd_log_raw(level, " "); + continue; + } + usbmuxd_log_raw(level, "%02x ", *(data + i + j) & 0xff); + } + usbmuxd_log_raw(level, " | "); + for (j = 0; j < 16; j++) { + if (i + j >= length) + break; + c = *(data + i + j); + if ((c < 32) || (c > 127)) { + usbmuxd_log_raw(level, "."); + continue; + } + usbmuxd_log_raw(level, "%c", c); + } + usbmuxd_log_raw(level, "\n"); + } +}
\ No newline at end of file @@ -39,6 +39,6 @@ void log_enable_syslog(); void log_disable_syslog(); void usbmuxd_log(enum loglevel level, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); - +void usbmuxd_log_buffer(enum loglevel level, const unsigned char *data, const size_t length); #endif |