aboutsummaryrefslogtreecommitdiff
path: root/example/ndpiReader.c
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2023-03-22 00:15:56 +0100
committerLuca Deri <deri@ntop.org>2023-03-22 00:15:56 +0100
commit64ebf73b2961f768ab52bdb05b4951bfe337f478 (patch)
tree966a45fd53c1b5992178a6f7d37bf02bf8607b24 /example/ndpiReader.c
parentb3457c644f5581c211697330e3f12d2ef83200aa (diff)
Added the ability to define custom protocols with arbitrary Ids in proto.txt
Example - ip:213.75.170.11/32:443@CustomProtocol nDPI assigns an is that can change based on protos.txt content - ip:213.75.170.11/32:443@CustomProtocol=9999 nDPI assigns 9999 as protocolId to CustomProtocol and won't change when protos.txt content will chaneg
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r--example/ndpiReader.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 20bc8a91b..02cb7364b 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -1905,6 +1905,8 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
struct ndpi_flow_info *flow = *(struct ndpi_flow_info **) node;
u_int16_t thread_id = *((u_int16_t *) user_data), proto;
+ if(flow == NULL) return;
+
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
if((!flow->detection_completed) && flow->ndpi_flow) {
u_int8_t proto_guessed;
@@ -1921,6 +1923,8 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
proto = flow->detected_protocol.app_protocol ? flow->detected_protocol.app_protocol : flow->detected_protocol.master_protocol;
+ proto = ndpi_map_user_proto_id_to_ndpi_id(ndpi_thread_info[thread_id].workflow->ndpi_struct, proto);
+
ndpi_thread_info[thread_id].workflow->stats.protocol_counter[proto] += flow->src2dst_packets + flow->dst2src_packets;
ndpi_thread_info[thread_id].workflow->stats.protocol_counter_bytes[proto] += flow->src2dst_bytes + flow->dst2src_bytes;
ndpi_thread_info[thread_id].workflow->stats.protocol_flows[proto]++;
@@ -3733,7 +3737,8 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
if(!quiet_mode) {
printf("\t%-20s packets: %-13llu bytes: %-13llu "
"flows: %-13u\n",
- ndpi_get_proto_name(ndpi_thread_info[0].workflow->ndpi_struct, i),
+ ndpi_get_proto_name(ndpi_thread_info[0].workflow->ndpi_struct,
+ ndpi_map_ndpi_id_to_user_proto_id(ndpi_thread_info[0].workflow->ndpi_struct, i)),
(long long unsigned int)cumulative_stats.protocol_counter[i],
(long long unsigned int)cumulative_stats.protocol_counter_bytes[i],
cumulative_stats.protocol_flows[i]);