summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/log.c27
-rw-r--r--src/log.h1
-rw-r--r--src/uanytun.c17
3 files changed, 28 insertions, 17 deletions
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);
+}
diff --git a/src/log.h b/src/log.h
index 70f4316..46ea867 100644
--- a/src/log.h
+++ b/src/log.h
@@ -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();