From b83eb7c7a2af62eee3187ca92b6f403f21b8d9c0 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Fri, 12 Apr 2024 19:47:24 +0200 Subject: Implemented STUN peer_address, relayed_address, response_origin, other_address parsing Added code to ignore invalid STUN realm Extended JSON output with STUN information --- example/reader_util.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'example/reader_util.c') 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 #include #endif +#include #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; -- cgit v1.2.3