diff options
author | Campus <campus@ntop.org> | 2016-11-03 23:10:23 +0100 |
---|---|---|
committer | Campus <campus@ntop.org> | 2016-11-03 23:10:23 +0100 |
commit | 7758bc821eceecd98ab08ed5cb4a73ac2e30e34e (patch) | |
tree | fe5620d3c962f9b1a2cff692b5f2bd3e65009e27 /src | |
parent | 58e97c966c3aef178580d8f362df95274fbe9c8a (diff) | |
parent | 78f7f1935973160c668327e41af2b59cafade874 (diff) |
Merge branch 'vpiserchia-dev' into dev
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_define.h | 23 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 31 |
2 files changed, 34 insertions, 20 deletions
diff --git a/src/include/ndpi_define.h b/src/include/ndpi_define.h index ce6149e5e..b632712a1 100644 --- a/src/include/ndpi_define.h +++ b/src/include/ndpi_define.h @@ -180,29 +180,22 @@ #define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600 #ifdef NDPI_ENABLE_DEBUG_MESSAGES - -#define NDPI_LOG(proto, m, log_level, args...) \ - { \ +#define NDPI_LOG(proto, m, log_level, args...) \ + { \ struct ndpi_detection_module_struct *mod = (struct ndpi_detection_module_struct*) m; \ - if(mod != NULL) { \ - mod->ndpi_debug_print_file=__FILE__; \ - mod->ndpi_debug_print_function=__FUNCTION__; \ - mod->ndpi_debug_print_line=__LINE__; \ - if (mod->ndpi_debug_printf != NULL) \ - mod->ndpi_debug_printf(proto, mod, log_level, args); \ - else \ - printf(args, proto, mod, log_level); \ - } \ + if(mod != NULL) { \ + mod->ndpi_debug_print_file=__FILE__; \ + mod->ndpi_debug_print_function=__FUNCTION__; \ + mod->ndpi_debug_print_line=__LINE__; \ + (*(mod->ndpi_debug_printf))(proto, mod, log_level, args); \ + } \ } - #else /* NDPI_ENABLE_DEBUG_MESSAGES */ - #ifdef WIN32 #define NDPI_LOG(...) {} #else #define NDPI_LOG(proto, mod, log_level, args...) {} #endif - #endif /* NDPI_ENABLE_DEBUG_MESSAGES */ /** diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index c8d2d3d7d..2f0b5c336 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -1714,12 +1714,29 @@ void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size)) { _ndpi_malloc = __ndp void set_ndpi_free(void (*__ndpi_free)(void *ptr)) { _ndpi_free = __ndpi_free; } +void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level, const char * format, ...) +{ +#ifdef NDPI_ENABLE_DEBUG_MESSAGES + va_list args; + #define MAX_STR_LEN 120 + char str[MAX_STR_LEN]; + va_start(args, format); + vsprintf(str, format, args); + va_end(args); + + if (ndpi_str != NULL) { + char proto_name[64]; + snprintf(proto_name, sizeof(proto_name), "%s", ndpi_get_proto_name(ndpi_str, proto)); + printf("%s:%s:%u - Proto: %s, %s\n", ndpi_str->ndpi_debug_print_file, ndpi_str->ndpi_debug_print_function, ndpi_str->ndpi_debug_print_line, proto_name, str); + } else { + printf("Proto: %u, %s\n", proto, str); + } +#endif +} + void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str, ndpi_debug_function_ptr ndpi_debug_printf) { #ifdef NDPI_ENABLE_DEBUG_MESSAGES - if (ndpi_debug_printf != NULL) - ndpi_str->ndpi_debug_printf = ndpi_debug_printf; - else - ndpi_str->ndpi_debug_printf = (ndpi_debug_function_ptr) printf; + ndpi_str->ndpi_debug_printf = ndpi_debug_printf; #endif } @@ -1731,11 +1748,15 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) { if(ndpi_str == NULL) { #ifdef NDPI_ENABLE_DEBUG_MESSAGES printf(0, NULL, NDPI_LOG_DEBUG, "ndpi_init_detection_module initial malloc failed\n"); -#endif +#endif /* NDPI_ENABLE_DEBUG_MESSAGES */ return NULL; } memset(ndpi_str, 0, sizeof(struct ndpi_detection_module_struct)); +#ifdef NDPI_ENABLE_DEBUG_MESSAGES + set_ndpi_debug_function(ndpi_str, (ndpi_debug_function_ptr)ndpi_debug_printf); +#endif /* NDPI_ENABLE_DEBUG_MESSAGES */ + if((ndpi_str->protocols_ptree = ndpi_New_Patricia(32 /* IPv4 */)) != NULL) ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, host_protocol_list); |