diff options
-rw-r--r-- | example/ndpiReader.c | 8 | ||||
-rw-r--r-- | example/reader_util.c | 25 | ||||
-rw-r--r-- | example/reader_util.h | 1 |
3 files changed, 32 insertions, 2 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index a626eb527..8854a7d23 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -3321,9 +3321,15 @@ static void ndpi_process_packet(u_char *args, * @brief Call pcap_loop() to process packets from a live capture or savefile */ static void runPcapLoop(u_int16_t thread_id) { - if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL)) + if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL)) { + int datalink_type = pcap_datalink(ndpi_thread_info[thread_id].workflow->pcap_handle); + if(!ndpi_is_datalink_supported(datalink_type)) { + printf("Unsupported datalink %d. Skip pcap\n", datalink_type); + return; + } if(pcap_loop(ndpi_thread_info[thread_id].workflow->pcap_handle, -1, &ndpi_process_packet, (u_char*)&thread_id) < 0) printf("Error while reading pcap file: '%s'\n", pcap_geterr(ndpi_thread_info[thread_id].workflow->pcap_handle)); + } } /** diff --git a/example/reader_util.c b/example/reader_util.c index 36c178176..222a5f3bb 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -1541,6 +1541,26 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow, return(flow->detected_protocol); } +int ndpi_is_datalink_supported(int datalink_type) +{ + /* Keep in sync with the similar switch in ndpi_workflow_process_packet */ + switch(datalink_type) { + case DLT_NULL: + case DLT_PPP_SERIAL: + case DLT_C_HDLC: + case DLT_PPP: + case DLT_IPV4: + case DLT_IPV6: + case DLT_EN10MB: + case DLT_LINUX_SLL: + case DLT_IEEE802_11_RADIO: + case DLT_RAW: + return 1; + default: + return 0; + } +} + /* ****************************************************** */ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, @@ -1623,6 +1643,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, if(header->caplen < eth_offset + 28) return(nproto); /* Too short */ + /* Keep in sync with ndpi_is_datalink_supported() */ switch(datalink_type) { case DLT_NULL: if(ntohl(*((u_int32_t*)&packet[eth_offset])) == 2) @@ -1737,7 +1758,9 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, break; default: - /* printf("Unknown datalink %d\n", datalink_type); */ + /* We shoudn't be here, because we already checked that this datalink is supported. + Should ndpi_is_datalink_supported() be updated? */ + printf("Unknown datalink %d\n", datalink_type); return(nproto); } diff --git a/example/reader_util.h b/example/reader_util.h index e317b4aa8..5ec8b558c 100644 --- a/example/reader_util.h +++ b/example/reader_util.h @@ -318,6 +318,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, const u_char *packet, FILE * csv_fp); +int ndpi_is_datalink_supported(int datalink_type); /* flow callbacks for complete detected flow (ndpi_flow_info will be freed right after) */ |