You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
3.1 KiB

From 6dcf1f3fbab782804339db5a3fe8cd0c88c07795 Mon Sep 17 00:00:00 2001
From: lucaderi <deri@ntop.org>
Date: Thu, 4 Oct 2018 21:36:46 +0200
Subject: [PATCH 6/9] Backported ndpi_protocol2id
---
src/include/ndpi_api.h | 17 +++++++++++++++--
src/lib/ndpi_main.c | 17 +++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index 56c5436..ccbad73 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -274,7 +274,7 @@ extern "C" {
*/
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
-
+
/**
* API call that is called internally by ndpi_detection_process_packet or by apps
* that want to avoid calling ndpi_detection_process_packet as they have already
@@ -432,6 +432,19 @@ extern "C" {
char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol proto, char *buf, u_int buf_len);
+ /**
+ * Same as ndpi_protocol2name() with the difference that the numeric protocol
+ * name is returned
+ *
+ * @par ndpi_mod = the detection module
+ * @par proto = the struct ndpi_protocol contain the protocols name
+ * @par buf = the buffer to write the name of the protocols
+ * @par buf_len = the length of the buffer
+ * @return the buffer contains the master_protocol and protocol name
+ *
+ */
+ char* ndpi_protocol2id(struct ndpi_detection_module_struct *ndpi_mod,
+ ndpi_protocol proto, char *buf, u_int buf_len);
/**
* Write the protocol name in the buffer -buf- as master_protocol.protocol (number)
*
@@ -746,7 +759,7 @@ extern "C" {
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_detection_module_size();
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
-
+
/**
* Add a string to match to an automata
*
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 33ccbb1..e1cf577 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -5319,6 +5319,23 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
/* ****************************************************** */
+char* ndpi_protocol2id(struct ndpi_detection_module_struct *ndpi_mod,
+ ndpi_protocol proto, char *buf, u_int buf_len) {
+ if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN)
+ && (proto.master_protocol != proto.app_protocol)) {
+ if(proto.app_protocol != NDPI_PROTOCOL_UNKNOWN)
+ snprintf(buf, buf_len, "%u.%u",
+ proto.master_protocol, proto.app_protocol);
+ else
+ snprintf(buf, buf_len, "%u", proto.master_protocol);
+ } else
+ snprintf(buf, buf_len, "%u", proto.app_protocol);
+
+ return(buf);
+}
+
+/* ****************************************************** */
+
char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol proto, char *buf, u_int buf_len) {
if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN)
--
2.19.1