From 556052777711b5969986fc06ba862548f7c04912 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 12 Mar 2009 22:00:41 +0000 Subject: moved hex-dump function to log_* --- src/log.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c index 08382cd..847baf7 100644 --- a/src/log.c +++ b/src/log.c @@ -229,3 +229,30 @@ void log_printf(log_prio_t prio, const char* fmt, ...) log_targets_log(&stdlog.targets_, prio, msg); } + +void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len) +{ + if(stdlog.max_prio_ < prio) + return; + + static char msg[MSG_LENGTH_MAX]; + + if(!buf) { + snprintf(msg, MSG_LENGTH_MAX, "(NULL)"); + } + else { + u_int32_t i; + int offset = snprintf(msg, MSG_LENGTH_MAX, "dump(%d): ", len); + if(offset < 0) + return; + u_int8_t* ptr = &msg[offset]; + + for(i=0; i < len; i++) { + if(((i+1)*3) >= (MSG_LENGTH_MAX - offset)) + break; + sprintf(ptr, "%02X ", buf[i]); + ptr+=3; + } + } + log_targets_log(&stdlog.targets_, prio, msg); +} -- cgit v1.2.3