diff options
author | Luca Deri <deri@ntop.org> | 2024-08-24 17:43:04 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2024-08-24 17:43:19 +0200 |
commit | f7ee92c690ebce8841f1ab973b3d63146952f912 (patch) | |
tree | fb3ea3ce40b4e12ad25ee580583c2ab1a6aabc11 | |
parent | 0a4198b35a2c8085942ba1055b1766000f2825c4 (diff) |
Added ndpi_get_protocol_by_name*( API call
-rw-r--r-- | src/include/ndpi_main.h | 3 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 26 |
2 files changed, 28 insertions, 1 deletions
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); +} + /* ************************************************************************************* */ /* ************************************************************************************* */ |