diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 27 | ||||
-rw-r--r-- | src/log.h | 1 | ||||
-rw-r--r-- | src/uanytun.c | 17 |
3 files changed, 28 insertions, 17 deletions
@@ -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); +} @@ -84,5 +84,6 @@ void log_close(); void update_max_prio(); int log_add_target(const char* conf); void log_printf(log_prio_t prio, const char* fmt, ...); +void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len); #endif diff --git a/src/uanytun.c b/src/uanytun.c index 396903d..5c81dc9 100644 --- a/src/uanytun.c +++ b/src/uanytun.c @@ -308,23 +308,6 @@ int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt) return return_value; } -void print_hex_dump(const u_int8_t* buf, u_int32_t len) -{ - if(!buf) { - printf("(NULL)"); - } - - u_int32_t i; - for(i=0; i < len; i++) { - printf("%02X ", buf[i]); - if(!((i+1)%8)) - printf(" "); - if(!((i+1)%16)) - printf("\n"); - } - printf("\n"); -} - int main(int argc, char* argv[]) { log_init(); |