From 7abe7c50ba3baa39071adf80f8a4cd567aed06ac Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Mon, 28 Oct 2024 13:24:54 +0100 Subject: Added ndpi_str_endswith() --- src/lib/ndpi_utils.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index 5f9a86188..4e981ed96 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -1272,7 +1272,7 @@ int ndpi_dpi2json(struct ndpi_detection_module_struct *ndpi_struct, ndpi_serialize_string_string(serializer, "hostname", host_server_name); ndpi_serialize_string_string(serializer, "domainame", ndpi_get_host_domain(ndpi_struct, host_server_name)); } - + switch(l7_protocol.proto.master_protocol ? l7_protocol.proto.master_protocol : l7_protocol.proto.app_protocol) { case NDPI_PROTOCOL_IP_ICMP: if(flow->entropy > 0.0f) { @@ -1654,7 +1654,7 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct, if(flow->tcp.fingerprint) ndpi_serialize_string_string(serializer, "tcp_fingerprint", flow->tcp.fingerprint); - + ndpi_serialize_string_string(serializer, "proto", ndpi_get_ip_proto_name(l4_protocol, l4_proto_name, sizeof(l4_proto_name))); @@ -3494,6 +3494,15 @@ char* ndpi_strrstr(const char *haystack, const char *needle) { return (char*) last_occurrence; } +/* ************************************************************** */ + +int ndpi_str_endswith(const char *s, const char *suffix) { + size_t slen = strlen(s); + size_t suffixlen = strlen(suffix); + + return((slen >= suffixlen) && (!memcmp(&s[slen - suffixlen], suffix, suffixlen))); +} + /* ******************************************* */ const char *ndpi_lru_cache_idx_to_name(lru_cache_type idx) @@ -3708,7 +3717,7 @@ u_int ndpi_hex2bin(u_char *out, u_int out_len, u_char* in, u_int in_len) { if(((in_len+1) / 2) > out_len) return(0); - + for(i=0, j=0; i