diff options
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r-- | example/ndpiReader.c | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 4be142d28..a03c461be 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -848,9 +848,6 @@ static void parseOptions(int argc, char **argv) { } } - if(_pcap_file[0] == NULL) - help(0); - if(csv_fp) printCSVHeader(); @@ -860,6 +857,9 @@ static void parseOptions(int argc, char **argv) { extcap_capture(); } + if(_pcap_file[0] == NULL) + help(0); + if(strchr(_pcap_file[0], ',')) { /* multiple ingress interfaces */ num_threads = 0; /* setting number of threads = number of interfaces */ __pcap_file = strtok(_pcap_file[0], ","); @@ -1828,13 +1828,13 @@ static void node_idle_scan_walker(const void *node, ndpi_VISIT which, int depth, /* update stats */ node_proto_guess_walker(node, which, depth, user_data); + if(verbose == 3) + port_stats_walker(node, which, depth, user_data); if((flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN) && !undetected_flows_deleted) undetected_flows_deleted = 1; - ndpi_free_flow_info_half(flow); - ndpi_free_flow_data_analysis(flow); - ndpi_free_flow_tls_data(flow); + ndpi_flow_info_free_data(flow); ndpi_thread_info[thread_id].workflow->stats.ndpi_flow_count--; /* adding to a queue (we can't delete it from the tree inline ) */ @@ -3094,6 +3094,10 @@ void test_lib() { } } +#ifdef USE_DPDK + dpdk_port_deinit(dpdk_port_id); +#endif + gettimeofday(&end, NULL); processing_time_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec); setup_time_usec = begin.tv_sec*1000000 + begin.tv_usec - (startup_time.tv_sec*1000000 + startup_time.tv_usec); @@ -3111,6 +3115,31 @@ void test_lib() { /* *********************************************** */ +static void binUnitTest() { + struct ndpi_bin b1, b2; + u_int8_t num_bins = 32; + u_int32_t i; + char out_buf[128]; + + srand(time(NULL)); + + ndpi_init_bin(&b1, ndpi_bin_family8, num_bins), ndpi_init_bin(&b2, ndpi_bin_family8, num_bins); + + for(i=0; i<32; i++) + ndpi_inc_bin(&b1, rand() % num_bins), ndpi_inc_bin(&b2, rand() % num_bins); + +#if 0 + printf("1) %s\n", ndpi_print_bin(&b1, 0, out_buf, sizeof(out_buf))); + printf("2) %s\n", ndpi_print_bin(&b2, 0, out_buf, sizeof(out_buf))); + + printf("Similarity: %f\n\n", ndpi_bin_similarity(&b1, &b2, 1)); +#endif + + ndpi_free_bin(&b1), ndpi_free_bin(&b2); +} + +/* *********************************************** */ + static void dgaUnitTest() { const char *dga[] = { "lbjamwptxz", @@ -3474,6 +3503,25 @@ void bpf_filter_port_array_add(int filter_array[], int size, int port) { /* *********************************************** */ +void analysisUnitTest() { + struct ndpi_analyze_struct *s = ndpi_alloc_data_analysis(32); + u_int32_t i; + + for(i=0; i<256; i++) + ndpi_data_add_value(s, i); + + if(0) { + ndpi_data_print_window_values(s); + printf("Average: [all: %f][window: %f]\n", ndpi_data_average(s), ndpi_data_window_average(s)); + printf("Entropy: %f\n", ndpi_data_entropy(s)); + printf("StdDev: %f\n", ndpi_data_stddev(s)); + printf("Min/Max: %u/%u\n", ndpi_data_min(s), ndpi_data_max(s)); + } + + ndpi_free_data_analysis(s); +} + +/* *********************************************** */ /** @brief MAIN FUNCTION @@ -3496,6 +3544,7 @@ int orginal_main(int argc, char **argv) { if(ndpi_info_mod == NULL) return -1; /* Internal checks */ + binUnitTest(); dgaUnitTest(); hllUnitTest(); bitmapUnitTest(); @@ -3503,7 +3552,7 @@ int orginal_main(int argc, char **argv) { serializerUnitTest(); analyzeUnitTest(); ndpi_self_check_host_match(); - + analysisUnitTest(); memset(ndpi_thread_info, 0, sizeof(ndpi_thread_info)); parseOptions(argc, argv); |