aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2021-07-23 10:37:20 +0200
committerGitHub <noreply@github.com>2021-07-23 10:37:20 +0200
commit6ad0d6666c5744713caa4eec4d43652680aaecab (patch)
treece8aa34398d2afe94d3d999d1b4577bd659da99f /example
parent8ea8ba8e9b52620989d515f0762be3ec906d4c30 (diff)
Implemented function to retrieve flow information. #1253 (#1254)
* fixed [h]euristic typo Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'example')
-rw-r--r--example/ndpiReader.c10
-rw-r--r--example/ndpiSimpleIntegration.c39
-rw-r--r--example/reader_util.c2
-rw-r--r--example/reader_util.h2
4 files changed, 37 insertions, 16 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 99b24874b..b44346506 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -61,7 +61,7 @@
#define ntohl64(x) ( ( (uint64_t)(ntohl( (uint32_t)((x << 32) >> 32) )) << 32) | ntohl( ((uint32_t)(x >> 32)) ) )
#define htonl64(x) ntohl64(x)
-#define EURISTICS_CODE 1
+#define HEURISTICS_CODE 1
/** Client parameters **/
@@ -1484,10 +1484,10 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
}
}
-#ifdef EURISTICS_CODE
- if(flow->ssh_tls.browser_euristics.is_safari_tls) fprintf(out, "[Safari]");
- if(flow->ssh_tls.browser_euristics.is_firefox_tls) fprintf(out, "[Firefox]");
- if(flow->ssh_tls.browser_euristics.is_chrome_tls) fprintf(out, "[Chrome]");
+#ifdef HEURISTICS_CODE
+ if(flow->ssh_tls.browser_heuristics.is_safari_tls) fprintf(out, "[Safari]");
+ if(flow->ssh_tls.browser_heuristics.is_firefox_tls) fprintf(out, "[Firefox]");
+ if(flow->ssh_tls.browser_heuristics.is_chrome_tls) fprintf(out, "[Chrome]");
#endif
if(flow->ssh_tls.notBefore && flow->ssh_tls.notAfter) {
diff --git a/example/ndpiSimpleIntegration.c b/example/ndpiSimpleIntegration.c
index dd679125c..42784697a 100644
--- a/example/ndpiSimpleIntegration.c
+++ b/example/ndpiSimpleIntegration.c
@@ -65,7 +65,8 @@ struct nDPI_flow_info {
uint8_t detection_completed:1;
uint8_t tls_client_hello_seen:1;
uint8_t tls_server_hello_seen:1;
- uint8_t reserved_00:2;
+ uint8_t flow_info_printed:1;
+ uint8_t reserved_00:1;
uint8_t l4_protocol;
struct ndpi_proto detected_l7_protocol;
@@ -857,10 +858,12 @@ static void ndpi_process_packet(uint8_t * const args,
flow_to_process->detection_completed == 0)
{
if (flow_to_process->detected_l7_protocol.master_protocol != NDPI_PROTOCOL_UNKNOWN ||
- flow_to_process->detected_l7_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN) {
- flow_to_process->detection_completed = 1;
- workflow->detected_flow_protocols++;
- printf("[%8llu, %d, %4d][DETECTED] protocol: %s | app protocol: %s | category: %s\n",
+ flow_to_process->detected_l7_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN)
+ {
+ flow_to_process->detection_completed = 1;
+ workflow->detected_flow_protocols++;
+
+ printf("[%8llu, %d, %4d][DETECTED] protocol: %s | app protocol: %s | category: %s\n",
workflow->packets_captured,
reader_thread->array_index,
flow_to_process->flow_id,
@@ -885,6 +888,20 @@ static void ndpi_process_packet(uint8_t * const args,
* EoE - End of Example
*/
+ if (flow_to_process->flow_info_printed == 0)
+ {
+ char const * const flow_info = ndpi_get_flow_info(flow_to_process->ndpi_flow, &flow_to_process->detected_l7_protocol);
+ if (flow_info != NULL)
+ {
+ printf("[%8llu, %d, %4d] info: %s\n",
+ workflow->packets_captured,
+ reader_thread->array_index,
+ flow_to_process->flow_id,
+ flow_info);
+ flow_to_process->flow_info_printed = 1;
+ }
+ }
+
if (flow_to_process->detected_l7_protocol.master_protocol == NDPI_PROTOCOL_TLS ||
flow_to_process->detected_l7_protocol.app_protocol == NDPI_PROTOCOL_TLS)
{
@@ -916,8 +933,10 @@ static void ndpi_process_packet(uint8_t * const args,
ndpi_ssl_version2str(flow_to_process->ndpi_flow,
flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.ssl_version,
&unknown_tls_version),
- flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.server_names_len,
- flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.server_names,
+ (flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.server_names_len == 0 ?
+ 1 : flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.server_names_len),
+ (flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.server_names == NULL ?
+ "-" : flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.server_names),
(flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.issuerDN != NULL ?
flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.issuerDN : "-"),
(flow_to_process->ndpi_flow->protos.tls_quic_stun.tls_quic.subjectDN != NULL ?
@@ -957,7 +976,7 @@ static void * processing_thread(void * const ndpi_thread_arg)
struct nDPI_reader_thread const * const reader_thread =
(struct nDPI_reader_thread *)ndpi_thread_arg;
- printf("Starting ThreadID %d\n", reader_thread->array_index);
+ printf("Starting Thread %d\n", reader_thread->array_index);
run_pcap_loop(reader_thread);
reader_thread->workflow->error_or_eof = 1;
return NULL;
@@ -1089,9 +1108,11 @@ int main(int argc, char ** argv)
"----------------------------------\n"
"nDPI version: %s\n"
" API version: %u\n"
+ "libgcrypt...: %s\n"
"----------------------------------\n",
argv[0],
- ndpi_revision(), ndpi_get_api_version());
+ ndpi_revision(), ndpi_get_api_version(),
+ (ndpi_get_gcrypt_version() == NULL ? "-" : ndpi_get_gcrypt_version()));
if (setup_reader_threads((argc >= 2 ? argv[1] : NULL)) != 0) {
fprintf(stderr, "%s: setup_reader_threads failed\n", argv[0]);
diff --git a/example/reader_util.c b/example/reader_util.c
index e53cb3f3b..e8bc5c9e4 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -1176,7 +1176,7 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
flow->ssh_tls.sha1_cert_fingerprint_set = 1;
}
- flow->ssh_tls.browser_euristics = flow->ndpi_flow->protos.tls_quic_stun.tls_quic.browser_euristics;
+ flow->ssh_tls.browser_heuristics = flow->ndpi_flow->protos.tls_quic_stun.tls_quic.browser_heuristics;
if(flow->ndpi_flow->protos.tls_quic_stun.tls_quic.alpn) {
if((flow->ssh_tls.tls_alpn = ndpi_strdup(flow->ndpi_flow->protos.tls_quic_stun.tls_quic.alpn)) != NULL)
diff --git a/example/reader_util.h b/example/reader_util.h
index 28ea6029e..0c584b378 100644
--- a/example/reader_util.h
+++ b/example/reader_util.h
@@ -211,7 +211,7 @@ typedef struct ndpi_flow_info {
ja3_client[33], ja3_server[33],
sha1_cert_fingerprint[20];
u_int8_t sha1_cert_fingerprint_set;
- struct tls_euristics browser_euristics;
+ struct tls_heuristics browser_heuristics;
struct {
u_int16_t cipher_suite;