diff options
author | emanuele-f <black.silver@hotmail.it> | 2016-04-19 23:35:35 +0200 |
---|---|---|
committer | emanuele-f <black.silver@hotmail.it> | 2016-04-19 23:35:35 +0200 |
commit | d7548e72b265198528279bd1ad87b04cdd6221c6 (patch) | |
tree | ed4b6c27f364ae2b6a67e57b484d23cecd3c4981 | |
parent | 7964e11c7fa043894aeaa064ceda5a696ca1e803 (diff) |
Fix some issues
-rw-r--r-- | example/ndpiReader.c | 30 | ||||
-rw-r--r-- | src/lib/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/ndpi_util.c | 1 |
3 files changed, 17 insertions, 15 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index c2cfcf33d..d86fb3f2b 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -109,7 +109,6 @@ static u_int32_t num_flows; struct reader_thread { struct ndpi_workflow * workflow; pthread_t pthread; - pcap_t * pcap_handle; }; static struct reader_thread ndpi_thread_info[MAX_NUM_READER_THREADS]; @@ -945,8 +944,8 @@ static void printResults(u_int64_t tot_usec) { /* ***************************************************** */ static void breakPcapLoop(u_int16_t thread_id) { - if(ndpi_thread_info[thread_id].pcap_handle != NULL) { - pcap_breakloop(ndpi_thread_info[thread_id].pcap_handle); + if(ndpi_thread_info[thread_id].workflow->pcap_handle != NULL) { + pcap_breakloop(ndpi_thread_info[thread_id].workflow->pcap_handle); } } @@ -1061,10 +1060,15 @@ static void pcap_packet_callback_checked(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { u_int16_t thread_id = *((u_int16_t*)args); - + + /* allocate an exact size buffer to check overflows */ + uint8_t *packet_checked = malloc(header->caplen); + memcpy(packet_checked, packet, header->caplen); + ndpi_workflow_process_packet(ndpi_thread_info[thread_id].workflow, header, packet_checked); + if((capture_until != 0) && (header->ts.tv_sec >= capture_until)) { - if(ndpi_thread_info[thread_id].pcap_handle != NULL) - pcap_breakloop(ndpi_thread_info[thread_id].pcap_handle); + if(ndpi_thread_info[thread_id].workflow->pcap_handle != NULL) + pcap_breakloop(ndpi_thread_info[thread_id].workflow->pcap_handle); return; } @@ -1073,11 +1077,7 @@ static void pcap_packet_callback_checked(u_char *args, if (!pcap_start.tv_sec) pcap_start.tv_sec = header->ts.tv_sec, pcap_start.tv_usec = header->ts.tv_usec; pcap_end.tv_sec = header->ts.tv_sec, pcap_end.tv_usec = header->ts.tv_usec; } - - /* allocate an exact size buffer to check overflows */ - uint8_t *packet_checked = malloc(header->caplen); - memcpy(packet_checked, packet, header->caplen); - ndpi_workflow_process_packet(ndpi_thread_info[thread_id].workflow, header, packet_checked); + /* check for buffer changes */ if(memcmp(packet, packet_checked, header->caplen) != 0) printf("INTERNAL ERROR: ingress packet was nodified by nDPI: this should not happen [thread_id=%u, packetId=%lu]\n", @@ -1088,8 +1088,8 @@ static void pcap_packet_callback_checked(u_char *args, /* ******************************************************************** */ static void runPcapLoop(u_int16_t thread_id) { - if((!shutdown_app) && (ndpi_thread_info[thread_id].pcap_handle != NULL)) - pcap_loop(ndpi_thread_info[thread_id].pcap_handle, -1, &pcap_packet_callback_checked, (u_char*)&thread_id); + if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL)) + pcap_loop(ndpi_thread_info[thread_id].workflow->pcap_handle, -1, &pcap_packet_callback_checked, (u_char*)&thread_id); } /* ******************************************************************** */ @@ -1120,8 +1120,8 @@ void *processing_thread(void *_thread_id) { char filename[256]; if(getNextPcapFileFromPlaylist(thread_id, filename, sizeof(filename)) == 0 && - (ndpi_thread_info[thread_id].pcap_handle = pcap_open_offline(filename, pcap_error_buffer)) != NULL) { - configurePcapHandle(ndpi_thread_info[thread_id].pcap_handle); + (ndpi_thread_info[thread_id].workflow->pcap_handle = pcap_open_offline(filename, pcap_error_buffer)) != NULL) { + configurePcapHandle(ndpi_thread_info[thread_id].workflow->pcap_handle); goto pcap_loop; } } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index d83fdd5c0..312cdc88c 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -16,6 +16,7 @@ libndpi_la_include_HEADERS = ../include/ndpi_api.h \ libndpi_la_SOURCES = ndpi_content_match.c.inc \ ndpi_main.c \ + ndpi_util.c \ protocols/afp.c \ protocols/aimini.c \ protocols/applejuice.c \ diff --git a/src/lib/ndpi_util.c b/src/lib/ndpi_util.c index 1bc75aad0..3028fd5b6 100644 --- a/src/lib/ndpi_util.c +++ b/src/lib/ndpi_util.c @@ -149,6 +149,7 @@ struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * pre workflow->idle_flows = ndpi_malloc(sizeof(struct ndpi_flow_info *) * workflow->num_idle_flows); workflow->ndpi_flows_root = ndpi_malloc(sizeof(void *) * workflow->prefs.num_roots); + return workflow; } void ndpi_workflow_free(struct ndpi_workflow * workflow) { |