aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2024-09-19 13:18:26 +0200
committerLuca Deri <deri@ntop.org>2024-09-19 13:18:26 +0200
commit191694f797639fc0b56adcf050bc9cfa8dc02f3d (patch)
tree58c51d7bfe0e346192a0296cf942aae2590da1eb /src
parent456bc2a52c06c16e12e01c5ec8426bc8783961c1 (diff)
Implemented ndpi_strrstr()
Fixed bug in ndpi_get_host_domain
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_api.h14
-rw-r--r--src/lib/ndpi_domains.c4
-rw-r--r--src/lib/ndpi_utils.c26
3 files changed, 33 insertions, 11 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index 1bc629b83..6e0e96e2f 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -1907,17 +1907,17 @@ extern "C" {
- https://varshasaini.in/k-nearest-neighbor-knn-algorithm-in-machine-learning/
NOTE:
- with ball tree, data is a vector of vector pointers (no array)
- */
+ with ball tree, data is a vector of vector pointers (no array)
+ */
ndpi_btree* ndpi_btree_init(double **data, u_int32_t n_rows, u_int32_t n_columns);
ndpi_knn ndpi_btree_query(ndpi_btree *b, double **query_data,
u_int32_t query_data_num_rows, u_int32_t query_data_num_columns,
u_int32_t max_num_results);
void ndpi_free_knn(ndpi_knn knn);
void ndpi_free_btree(ndpi_btree *tree);
-
+
/* ******************************* */
-
+
/*
* Finds outliers using Z-score
* Z-Score = (Value - Mean) / StdDev
@@ -2288,8 +2288,8 @@ extern "C" {
int64_t ndpi_strtonum(const char *numstr, int64_t minval, int64_t maxval, const char **errstrp, int base);
int ndpi_vsnprintf(char * str, size_t size, char const * format, va_list va_args);
int ndpi_snprintf(char * str, size_t size, char const * format, ...);
- struct tm *ndpi_gmtime_r(const time_t *timep,
- struct tm *result);
+ struct tm *ndpi_gmtime_r(const time_t *timep, struct tm *result);
+ char* ndpi_strrstr(const char *haystack, const char *needle);
/* ******************************* */
@@ -2309,7 +2309,7 @@ extern "C" {
bool ndpi_serialize_flow_fingerprint(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow, ndpi_serializer *serializer);
-
+
/* ******************************* */
const char *ndpi_lru_cache_idx_to_name(lru_cache_type idx);
diff --git a/src/lib/ndpi_domains.c b/src/lib/ndpi_domains.c
index f4398b1c8..00ef8e756 100644
--- a/src/lib/ndpi_domains.c
+++ b/src/lib/ndpi_domains.c
@@ -122,7 +122,7 @@ const char* ndpi_get_host_domain_suffix(struct ndpi_detection_module_struct *ndp
return(hostname);
}
-/* ******************************* */
+
/*
Example
@@ -146,7 +146,7 @@ const char* ndpi_get_host_domain(struct ndpi_detection_module_struct *ndpi_str,
if((ret == NULL) || (ret == hostname))
return(hostname);
- dot = strstr(hostname, ret);
+ dot = ndpi_strrstr(hostname, ret);
if(dot == NULL || dot == hostname)
return(hostname);
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index 6a2e237a3..a1b0a5e6e 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -3424,8 +3424,8 @@ int tpkt_verify_hdr(const struct ndpi_packet_struct * const packet)
/* ******************************************* */
-int64_t ndpi_strtonum(const char *numstr, int64_t minval, int64_t maxval, const char **errstrp, int base)
-{
+int64_t ndpi_strtonum(const char *numstr, int64_t minval,
+ int64_t maxval, const char **errstrp, int base) {
int64_t val = 0;
char* endptr;
@@ -3441,14 +3441,17 @@ int64_t ndpi_strtonum(const char *numstr, int64_t minval, int64_t maxval, const
*errstrp = "value too small";
return 0;
}
+
if((val == LLONG_MAX && errno == ERANGE) || (val > maxval )) {
*errstrp = "value too large";
return 0;
}
+
if(errno != 0 && val == 0) {
*errstrp = "generic error";
return 0;
}
+
if(endptr == numstr) {
*errstrp = "No digits were found";
return 0;
@@ -3459,6 +3462,25 @@ int64_t ndpi_strtonum(const char *numstr, int64_t minval, int64_t maxval, const
return val;
}
+/* ****************************************************** */
+
+char* ndpi_strrstr(const char *haystack, const char *needle) {
+ char *ret = NULL;
+
+ while(true) {
+ char *s = strstr(haystack, needle);
+
+ if(s == NULL)
+ break;
+ else {
+ ret = s;
+ haystack = &s[1]; /* Skip the first char */
+ }
+ }
+
+ return(ret);
+}
+
/* ******************************************* */
const char *ndpi_lru_cache_idx_to_name(lru_cache_type idx)