aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ndpi_domains.c4
-rw-r--r--src/lib/ndpi_utils.c26
2 files changed, 26 insertions, 4 deletions
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)