Skip to content

Commit

Permalink
Added ndpi_network_ptree6_match() API call
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Jan 31, 2025
1 parent dd4807f commit 71bd585
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/include/ndpi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ extern "C" {
*/
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct,
struct in_addr *pin);
u_int16_t ndpi_network_ptree6_match(struct ndpi_detection_module_struct *ndpi_str,
struct in6_addr *pin);

/**
* Returns the nDPI protocol id for IP+port-based protocol detection
Expand Down
18 changes: 18 additions & 0 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,24 @@ u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_str

/* ******************************************* */

u_int16_t ndpi_network_ptree6_match(struct ndpi_detection_module_struct *ndpi_str,
struct in6_addr *pin) {
ndpi_prefix_t prefix;
ndpi_patricia_node_t *node;

if(!ndpi_str || !ndpi_str->protocols)
return(NDPI_PROTOCOL_UNKNOWN);

/* Make sure all in network byte order otherwise compares wont work */
ndpi_fill_prefix_v6(&prefix, pin, 128,
((ndpi_patricia_tree_t *) ndpi_str->protocols->v4)->maxbits);
node = ndpi_patricia_search_best(ndpi_str->protocols->v4, &prefix);

return(node ? node->value.u.uv16[0].user_value : NDPI_PROTOCOL_UNKNOWN);
}

/* ******************************************* */

u_int16_t ndpi_network_port_ptree_match(struct ndpi_detection_module_struct *ndpi_str,
struct in_addr *pin /* network byte order */,
u_int16_t port /* network byte order */) {
Expand Down

0 comments on commit 71bd585

Please sign in to comment.