diff options
author | Luca Deri <deri@ntop.org> | 2024-04-12 19:47:24 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2024-04-12 19:50:04 +0200 |
commit | b83eb7c7a2af62eee3187ca92b6f403f21b8d9c0 (patch) | |
tree | 57f483c8eef99ea5c89eccfb01156a0261a51096 /example/reader_util.c | |
parent | 31de94ba1209c95c856236c15fd2765aa4db8f3f (diff) |
Implemented STUN peer_address, relayed_address, response_origin, other_address parsing
Added code to ignore invalid STUN realm
Extended JSON output with STUN information
Diffstat (limited to 'example/reader_util.c')
-rw-r--r-- | example/reader_util.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/example/reader_util.c b/example/reader_util.c index 252e3eeb0..e0e09ac61 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -1,7 +1,7 @@ /* * reader_util.c * - * Copyright (C) 2011-23 - ntop.org + * Copyright (C) 2011-24 - ntop.org * * This file is part of nDPI, an open source deep packet inspection * library based on the OpenDPI and PACE technology by ipoque GmbH @@ -42,6 +42,7 @@ #include <netinet/in.h> #include <netinet/ip.h> #endif +#include <assert.h> #include "reader_util.h" @@ -1077,11 +1078,13 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl u_int j; if(flow->ndpi_flow->protos.bittorrent.hash[0] != '\0') { - flow->bittorent_hash = ndpi_malloc(sizeof(flow->ndpi_flow->protos.bittorrent.hash) * 2 + 1); + u_int avail = sizeof(flow->ndpi_flow->protos.bittorrent.hash) * 2 + 1; + flow->bittorent_hash = ndpi_malloc(avail); if(flow->bittorent_hash) { + for(i=0, j = 0; i < sizeof(flow->ndpi_flow->protos.bittorrent.hash); i++) { - sprintf(&flow->bittorent_hash[j], "%02x", + snprintf(&flow->bittorent_hash[j], avail-j, "%02x", flow->ndpi_flow->protos.bittorrent.hash[i]); j += 2; @@ -1311,11 +1314,11 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl } } - if(flow->ndpi_flow->stun.mapped_address.port) { - memcpy(&flow->stun.mapped_address.address, &flow->ndpi_flow->stun.mapped_address.address, 16); - flow->stun.mapped_address.port = flow->ndpi_flow->stun.mapped_address.port; - flow->stun.mapped_address.is_ipv6 = flow->ndpi_flow->stun.mapped_address.is_ipv6; - } + memcpy(&flow->stun.mapped_address, &flow->ndpi_flow->stun.mapped_address, sizeof(ndpi_address_port)); + memcpy(&flow->stun.peer_address, &flow->ndpi_flow->stun.peer_address, sizeof(ndpi_address_port)); + memcpy(&flow->stun.relayed_address, &flow->ndpi_flow->stun.relayed_address, sizeof(ndpi_address_port)); + memcpy(&flow->stun.response_origin, &flow->ndpi_flow->stun.response_origin, sizeof(ndpi_address_port)); + memcpy(&flow->stun.other_address, &flow->ndpi_flow->stun.other_address, sizeof(ndpi_address_port)); flow->multimedia_flow_type = flow->ndpi_flow->flow_multimedia_type; |