From f7ee92c690ebce8841f1ab973b3d63146952f912 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Sat, 24 Aug 2024 17:43:04 +0200 Subject: Added ndpi_get_protocol_by_name*( API call --- src/include/ndpi_main.h | 3 ++- src/lib/ndpi_main.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/include/ndpi_main.h b/src/include/ndpi_main.h index 856c1227d..1b8de4558 100644 --- a/src/include/ndpi_main.h +++ b/src/include/ndpi_main.h @@ -71,7 +71,8 @@ extern "C" { extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id); u_int16_t ndpi_get_proto_by_name(struct ndpi_detection_module_struct *ndpi_mod, const char *name); - + ndpi_master_app_protocol ndpi_get_protocol_by_name(struct ndpi_detection_module_struct *ndpi_str, const char *name); + extern u_int8_t ndpi_is_proto(ndpi_protocol proto, u_int16_t p); extern void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index ae1d546e4..8973e5536 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -298,6 +298,32 @@ u_int16_t ndpi_get_proto_by_name(struct ndpi_detection_module_struct *ndpi_str, return(NDPI_PROTOCOL_UNKNOWN); } +/* *********************************************************************************** */ + +/* NOTE: supported both HTTP and TLS.YouTube */ +ndpi_master_app_protocol ndpi_get_protocol_by_name(struct ndpi_detection_module_struct *ndpi_str, const char *name) { + char *dot, buf[256]; + ndpi_master_app_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN }; + + if(!ndpi_str || !name) + return(ret); + + snprintf(buf, sizeof(buf), "%s", name); + dot = strchr(buf, '.'); + + if(dot) { + /* TLS.YouTube */ + dot[0] = '\0'; + ret.app_protocol = ndpi_get_proto_by_name(ndpi_str, &dot[1]); + } else { + /* TLS */ + } + + ret.master_protocol = ndpi_get_proto_by_name(ndpi_str, buf); /* both cases */ + + return(ret); +} + /* ************************************************************************************* */ /* ************************************************************************************* */ -- cgit v1.2.3