From 931f51bd77b2b863cab010064d2a2d0b4f968f7e Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Mon, 20 Jan 2020 23:37:09 +0100 Subject: ndpi_load_categories_file() now returns the number of loaded hosts or -1 in case of error --- src/lib/ndpi_main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 088847c8a..90c9a81a4 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -2846,7 +2846,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_str, int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str, const char* path) { char buffer[512], *line, *name, *category, *saveptr; FILE *fd; - int len; + int len, num = 0; fd = fopen(path, "r"); @@ -2872,15 +2872,19 @@ int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str, con if(name) { category = strtok_r(NULL, "\t", &saveptr); - if(category) - ndpi_load_category(ndpi_str, name, (ndpi_protocol_category_t) atoi(category)); + if(category) { + int rc = ndpi_load_category(ndpi_str, name, (ndpi_protocol_category_t) atoi(category)); + + if(rc >= 0) + num++; + } } } fclose(fd); ndpi_enable_loaded_categories(ndpi_str); - return(0); + return(num); } /* ******************************************************************** */ -- cgit v1.2.3