aboutsummaryrefslogtreecommitdiff
path: root/example/ndpiReader.c
diff options
context:
space:
mode:
authorLuca <deri@ntop.org>2024-01-15 19:03:46 +0100
committerLuca <deri@ntop.org>2024-01-15 19:03:46 +0100
commit162c38f18f81a4e069db5f957c13f68c2cdc9b89 (patch)
tree33555b3e246c83832c0e3a99fda75912ba686461 /example/ndpiReader.c
parent61a18623e71626b4c9197f171ca219fae6f5792b (diff)
Added new API calls
- ndpi_load_domain_suffixes() - ndpi_get_host_domain_suffix() whose goal is to find the domain name of a hostname. Example: www.bbc.co.uk -> co.uk mail.apple.com -> com
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r--example/ndpiReader.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 6cc01ed5d..5c050991b 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -5633,6 +5633,29 @@ void outlierUnitTest() {
/* *********************************************** */
+void domainsUnitTest() {
+ NDPI_PROTOCOL_BITMASK all;
+ struct ndpi_detection_module_struct *ndpi_info_mod = ndpi_init_detection_module(init_prefs);
+ const char *lists_path = "../lists/public_suffix_list.dat";
+ struct stat st;
+
+ if(stat(lists_path, &st) == 0) {
+ NDPI_BITMASK_SET_ALL(all);
+ ndpi_set_protocol_detection_bitmask2(ndpi_info_mod, &all);
+
+ assert(ndpi_load_domain_suffixes(ndpi_info_mod, "../lists/public_suffix_list.dat") == 0);
+
+ assert(strcmp(ndpi_get_host_domain_suffix(ndpi_info_mod, "www.chosei.chiba.jp"), "chosei.chiba.jp") == 0);
+ assert(strcmp(ndpi_get_host_domain_suffix(ndpi_info_mod, "www.unipi.it"), "it") == 0);
+ assert(strcmp(ndpi_get_host_domain_suffix(ndpi_info_mod, "mail.apple.com"), "com") == 0);
+ assert(strcmp(ndpi_get_host_domain_suffix(ndpi_info_mod, "www.bbc.co.uk"), "co.uk") == 0);
+
+ ndpi_exit_detection_module(ndpi_info_mod);
+ }
+}
+
+/* *********************************************** */
+
void domainSearchUnitTest() {
ndpi_domain_classify *sc = ndpi_domain_classify_alloc();
char *domain = "ntop.org";
@@ -5702,7 +5725,6 @@ int main(int argc, char **argv) {
}
#endif
-
if(ndpi_get_api_version() != NDPI_API_VERSION) {
printf("nDPI Library version mismatch: please make sure this code and the nDPI library are in sync\n");
return(-1);
@@ -5721,6 +5743,7 @@ int main(int argc, char **argv) {
exit(0);
#endif
+ domainsUnitTest();
outlierUnitTest();
pearsonUnitTest();
binaryBitmapUnitTest();