diff options
author | Alexander Czyrny <mail@czyrny.net> | 2020-04-16 14:12:48 +0200 |
---|---|---|
committer | Alexander Czyrny <mail@czyrny.net> | 2020-04-16 14:12:48 +0200 |
commit | 32d25bfdaf700ddb22085f662854cc62b2f2e8ec (patch) | |
tree | b33f30f8ccec80ba6fd020d6d3b08ebfe4480a27 /example/reader_util.c | |
parent | 287015ffdc33ff2c212563ffb866b38dee64e12b (diff) |
additional csv semicolon fix
Created function correct_csv_data_field to pevent duplicated code. Additionally used for _flow->ndpi_flow->protos.stun_ssl.ssl.alpn_ and _flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions_ to guarantee a valid csv output (commas replaced by semicolon) .
Diffstat (limited to 'example/reader_util.c')
-rw-r--r-- | example/reader_util.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/example/reader_util.c b/example/reader_util.c index 8b7bc1c75..94aafca2f 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -965,6 +965,13 @@ static u_int8_t is_ndpi_proto(struct ndpi_flow_info *flow, u_int16_t id) { /* ****************************************************** */ +void correct_csv_data_field(char* data) { + /* Replace , with ; to avoid issues with CSVs */ + for(u_int i=0; data[i] != '\0'; i++) if(data[i] == ',') data[i] = ';'; +} + +/* ****************************************************** */ + void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow) { u_int i; @@ -1095,27 +1102,28 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl } if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn) { - if((flow->ssh_tls.tls_alpn = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.alpn)) != NULL) { - /* Replace , with ; to avoid issues with CSVs */ - for(i=0; flow->ssh_tls.tls_alpn[i] != '\0'; i++) if(flow->ssh_tls.tls_alpn[i] == ',') flow->ssh_tls.tls_alpn[i] = ';'; - } + if((flow->ssh_tls.tls_alpn = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.alpn)) != NULL) + correct_csv_data_field(flow->ssh_tls.tls_alpn); } if(flow->ssh_tls.tls_supported_versions) { - if((flow->ssh_tls.tls_supported_versions = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions)) != NULL) { - /* Replace , with ; to avoid issues with CSVs */ - for(i=0; flow->ssh_tls.tls_supported_versions[i] != '\0'; i++) if(flow->ssh_tls.tls_supported_versions[i] == ',') flow->ssh_tls.tls_supported_versions[i] = ';'; - } + if((flow->ssh_tls.tls_supported_versions = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions)) != NULL) + correct_csv_data_field(flow->ssh_tls.tls_supported_versions); } if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn - && flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions) - snprintf(flow->info, sizeof(flow->info), "ALPN: %s][TLS Supported Versions: %s", - flow->ndpi_flow->protos.stun_ssl.ssl.alpn, - flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions); - else if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn) + && flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions) { + correct_csv_data_field(flow->ndpi_flow->protos.stun_ssl.ssl.alpn); + correct_csv_data_field(flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions); + snprintf(flow->info, sizeof(flow->info), "ALPN: %s][TLS Supported Versions: %s", + flow->ndpi_flow->protos.stun_ssl.ssl.alpn, + flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions); + } + else if(flow->ndpi_flow->protos.stun_ssl.ssl.alpn) { + correct_csv_data_field(flow->ndpi_flow->protos.stun_ssl.ssl.alpn); snprintf(flow->info, sizeof(flow->info), "ALPN: %s", flow->ndpi_flow->protos.stun_ssl.ssl.alpn); + } } if(flow->detection_completed && (!flow->check_extra_packets)) { |