Add function to search host in custom categories

This commit is contained in:
emanuele-f
2018-10-10 13:29:49 +02:00
parent 6ff6c2e5af
commit cdf197ccfe
2 changed files with 38 additions and 0 deletions
+2
View File
@@ -738,6 +738,8 @@ extern "C" {
void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol *ret);
int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct,
char *name_or_ip, unsigned long *id);
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_detection_preference pref,
int value);
+36
View File
@@ -2366,6 +2366,42 @@ static int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_
/* *********************************************** */
int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct,
char *name_or_ip, unsigned long *id) {
char ipbuf[64];
struct in_addr pin;
if(!ndpi_struct->custom_categories.categories_loaded)
return -1;
strncpy(ipbuf, name_or_ip, sizeof(ipbuf));
char *ptr = strrchr(ipbuf, '/');
if(ptr)
ptr[0] = '\0';
if(inet_pton(AF_INET, ipbuf, &pin) == 1) {
/* Search IP */
prefix_t prefix;
patricia_node_t *node;
/* Make sure all in network byte order otherwise compares wont work */
fill_prefix_v4(&prefix, &pin, 32, ((patricia_tree_t*)ndpi_struct->protocols_ptree)->maxbits);
node = ndpi_patricia_search_best(ndpi_struct->custom_categories.ipAddresses, &prefix);
if(node) {
*id = node->value.user_value;
return 0;
}
return(-1);
} else
/* Search Host */
return ndpi_match_custom_category(ndpi_struct, name_or_ip, id);
}
/* *********************************************** */
static void free_ptree_data(void *data) { ; }
/* ****************************************************** */