diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2022-09-24 23:25:33 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2022-09-25 00:54:39 +0200 |
commit | 2103ee0811e3f606b8129d044e22cd33804e2117 (patch) | |
tree | 80e76fd406e5f6dbf745ca39fa6d55d85790c530 /nDPId.c | |
parent | 36f1786bde2572cf7eb44aa1384b61ecfebdeff3 (diff) |
Refactored client distributor C API.
* Still not perfect, but the code before was not even able to deal with JSON arrays.
Use common "speaking" function names for all functions in nDPIsrvd.h
* Provide a more or less generic and easy extendable JSON walk function.
* Modified C examples to align with the changed C API.
* c-collectd: Reduced lot's of code duplication by providing mapping tables.
* nDPId: IAT array requires one slot less (first packet has always an IAT of 0).
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'nDPId.c')
-rw-r--r-- | nDPId.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -1356,7 +1356,8 @@ static int alloc_detection_data(struct nDPId_flow * const flow) goto error; } - ndpi_init_data_analysis(&flow->flow_extended.flow_analysis->iat, nDPId_options.max_packets_per_flow_to_analyse); + ndpi_init_data_analysis(&flow->flow_extended.flow_analysis->iat, + nDPId_options.max_packets_per_flow_to_analyse - 1 /* first packet IAT is always 0 */); ndpi_init_data_analysis(&flow->flow_extended.flow_analysis->pktlen, nDPId_options.max_packets_per_flow_to_analyse); flow->flow_extended.flow_analysis->directions = (uint8_t *)ndpi_malloc( @@ -2429,7 +2430,7 @@ static void jsonize_data_analysis(struct nDPId_reader_thread * const reader_thre ndpi_serialize_string_float(&workflow->ndpi_serializer, "ent", ndpi_data_entropy(&analysis->iat), "%.1f"); ndpi_serialize_start_of_list(&workflow->ndpi_serializer, "data"); - for (uint16_t i = 0; i < analysis->iat.num_values_array_len; ++i) + for (uint16_t i = 0; i < ndpi_min(analysis->iat.num_data_entries, analysis->iat.num_values_array_len); ++i) { ndpi_serialize_string_uint32(&workflow->ndpi_serializer, "", analysis->iat.values[i]); } @@ -2445,7 +2446,8 @@ static void jsonize_data_analysis(struct nDPId_reader_thread * const reader_thre ndpi_serialize_string_float(&workflow->ndpi_serializer, "ent", ndpi_data_entropy(&analysis->pktlen), "%.1f"); ndpi_serialize_start_of_list(&workflow->ndpi_serializer, "data"); - for (uint16_t i = 0; i < analysis->pktlen.num_values_array_len; ++i) + for (uint16_t i = 0; i < ndpi_min(analysis->pktlen.num_data_entries, analysis->pktlen.num_values_array_len); + ++i) { ndpi_serialize_string_uint32(&workflow->ndpi_serializer, "", analysis->pktlen.values[i]); } |