Skip to content

Commit

Permalink
Added ndpi_str_endswith()
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Oct 28, 2024
1 parent ecd3c73 commit 7abe7c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/include/ndpi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ extern "C" {

u_int ndpi_hex2bin(u_char *out, u_int out_len, u_char* in, u_int in_len);
u_int ndpi_bin2hex(u_char *out, u_int out_len, u_char* in, u_int in_len);

/* ******************************* */

int ndpi_des_init(struct ndpi_des_struct *des, double alpha, double beta, float significance);
Expand Down Expand Up @@ -2301,6 +2301,7 @@ extern "C" {
int ndpi_snprintf(char * str, size_t size, char const * format, ...);
struct tm *ndpi_gmtime_r(const time_t *timep, struct tm *result);
char* ndpi_strrstr(const char *haystack, const char *needle);
int ndpi_str_endswith(const char *s, const char *suffix);

/* ******************************* */

Expand All @@ -2322,16 +2323,16 @@ extern "C" {
u_int16_t cleartext_msg_len,
u_int16_t *encrypted_msg_len,
u_char encrypt_key[64]);

char* ndpi_quick_decrypt(const char *encrypted_msg,
u_int16_t encrypted_msg_len,
u_int16_t *decrypted_msg_len,
u_char decrypt_key[64]);

/* ******************************* */

const char* ndpi_print_os_hint(u_int8_t os_hint);

/* ******************************* */

bool ndpi_serialize_flow_fingerprint(struct ndpi_detection_module_struct *ndpi_str,
Expand All @@ -2348,7 +2349,7 @@ extern "C" {
u_int32_t epoch_now, u_int32_t ttl);
bool ndpi_address_cache_dump(struct ndpi_address_cache *cache, char *path, u_int32_t epoch_now);
u_int32_t ndpi_address_cache_restore(struct ndpi_address_cache *cache, char *path, u_int32_t epoch_now);


bool ndpi_cache_address(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_ip_addr_t ip_addr, char *hostname,
Expand All @@ -2357,7 +2358,7 @@ extern "C" {
bool ndpi_cache_address_dump(struct ndpi_detection_module_struct *ndpi_struct, char *path, u_int32_t epoch_now);
u_int32_t ndpi_cache_address_restore(struct ndpi_detection_module_struct *ndpi_struct, char *path, u_int32_t epoch_now);
u_int32_t ndpi_cache_address_flush_expired(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t epoch_now);

/* ******************************* */

const char *ndpi_lru_cache_idx_to_name(lru_cache_type idx);
Expand Down
23 changes: 16 additions & 7 deletions src/lib/ndpi_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<in_len; i += 2, j++) {
char buf[3];

Expand Down Expand Up @@ -3784,7 +3793,7 @@ char* ndpi_quick_encrypt(const char *cleartext_msg,
ndpi_free(encoded_buf);

*encrypted_msg_len = strlen(encoded);

return(encoded);
}

Expand All @@ -3803,7 +3812,7 @@ char* ndpi_quick_decrypt(const char *encrypted_msg,
struct AES_ctx ctx;

*decrypted_msg_len = 0;

if(decoded_string == NULL) {
/* Allocation failure */
return(NULL);
Expand Down Expand Up @@ -3839,7 +3848,7 @@ char* ndpi_quick_decrypt(const char *encrypted_msg,
}

*decrypted_msg_len = content_len;

ndpi_free(content);

return(decoded_string);
Expand All @@ -3849,7 +3858,7 @@ char* ndpi_quick_decrypt(const char *encrypted_msg,

const char* ndpi_print_os_hint(u_int8_t os_hint) {
switch(os_hint) {
case os_hint_windows: return("Windows");
case os_hint_windows: return("Windows");
case os_hint_macos: return("macOS");
case os_hint_ios_ipad_os: return("iOS/iPad");
case os_hint_android: return("Android");
Expand Down

0 comments on commit 7abe7c5

Please sign in to comment.