From 67dbcb7375bd5dc49c5e4050bba9aa4ac7a87b11 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Fri, 4 Oct 2019 07:19:20 +0000 Subject: Fixed invalid network searchthat caused categories to be set randomly --- src/lib/ndpi_main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index d362061fe..4fb3b68cf 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -4417,16 +4417,21 @@ int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_str prefix_t prefix; patricia_node_t *node; - /* Make sure all in network byte order otherwise compares wont work */ - fill_prefix_v4(&prefix, (struct in_addr *)&saddr, - 32, ((patricia_tree_t*)ndpi_str->protocols_ptree)->maxbits); - node = ndpi_patricia_search_best(ndpi_str->custom_categories.ipAddresses, &prefix); - - if(!node) { - fill_prefix_v4(&prefix, (struct in_addr *)&daddr, + if(saddr == 0) + node = NULL; + else { + /* Make sure all in network byte order otherwise compares wont work */ + fill_prefix_v4(&prefix, (struct in_addr *)&saddr, 32, ((patricia_tree_t*)ndpi_str->protocols_ptree)->maxbits); node = ndpi_patricia_search_best(ndpi_str->custom_categories.ipAddresses, &prefix); } + + if(!node) { + if(daddr != 0) + fill_prefix_v4(&prefix, (struct in_addr *)&daddr, + 32, ((patricia_tree_t*)ndpi_str->protocols_ptree)->maxbits); + node = ndpi_patricia_search_best(ndpi_str->custom_categories.ipAddresses, &prefix); + } if(node) { ret->category = (ndpi_protocol_category_t)node->value.user_value; -- cgit v1.2.3