diff options
author | Luca <deri@ntop.org> | 2024-01-16 06:56:51 +0100 |
---|---|---|
committer | Luca <deri@ntop.org> | 2024-01-16 06:56:51 +0100 |
commit | 1637a991a4561a4ad16b1e0822065a273c60781f (patch) | |
tree | 77416ff5d9d3b0afd30d461284d9a9418d8d9084 /src/lib/ndpi_domain_classify.c | |
parent | 111015b872c3535a69a2c5a475845adf94818276 (diff) |
Added ndpi_get_host_domain() for returning the host domain
vs ndpi_get_host_domain_prefix() that instead returnd the host TLD
Diffstat (limited to 'src/lib/ndpi_domain_classify.c')
-rw-r--r-- | src/lib/ndpi_domain_classify.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/ndpi_domain_classify.c b/src/lib/ndpi_domain_classify.c index edec6afcd..00c491b4a 100644 --- a/src/lib/ndpi_domain_classify.c +++ b/src/lib/ndpi_domain_classify.c @@ -217,9 +217,10 @@ static bool is_valid_domain_char(u_char c) { const char* ndpi_domain_classify_longest_prefix(ndpi_domain_classify *s, u_int8_t *class_id /* out */, - const char *hostname) { + const char *hostname, + bool return_subprefix) { u_int32_t i, len; - const char *dot, *elem; + const char *dot, *elem, *prev_elem; *class_id = 0; /* Unknown class_id */ @@ -245,7 +246,7 @@ const char* ndpi_domain_classify_longest_prefix(ndpi_domain_classify *s, return(hostname); } - elem = hostname; + elem = prev_elem = hostname; while(elem != NULL) { u_int64_t hash = ndpi_quick_hash64(elem, strlen(elem)); @@ -257,7 +258,7 @@ const char* ndpi_domain_classify_longest_prefix(ndpi_domain_classify *s, printf("[contains] %s = %d\n", hostname, s->classes[i].class_id); #endif *class_id = s->classes[i].class_id; - return(elem); + return(return_subprefix ? prev_elem : elem); } } else break; @@ -268,6 +269,7 @@ const char* ndpi_domain_classify_longest_prefix(ndpi_domain_classify *s, if(elem == NULL) break; // if(elem == dot) break; + prev_elem = elem; elem = &elem[1]; } /* while */ @@ -280,7 +282,7 @@ const char* ndpi_domain_classify_longest_prefix(ndpi_domain_classify *s, bool ndpi_domain_classify_contains(ndpi_domain_classify *s, u_int8_t *class_id /* out */, const char *domain) { - (void)ndpi_domain_classify_longest_prefix(s, class_id, domain); /* UNUSED */ + (void)ndpi_domain_classify_longest_prefix(s, class_id, domain, false); /* UNUSED */ return((*class_id == 0) ? false : true); } |