From a6029d250d9c5dd0d7346fe47de838c243c20cac Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:47:29 +0100 Subject: ndpiReader: print an error msg if we found an unsupported datalink type (#1157) --- example/reader_util.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'example/reader_util.c') 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); } -- cgit v1.2.3