aboutsummaryrefslogtreecommitdiff
path: root/example/ndpiReader.c
diff options
context:
space:
mode:
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r--example/ndpiReader.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 919a7963d..cc62d0d49 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -2643,6 +2643,77 @@ static void debug_printf(u_int32_t protocol, void *id_struct,
/* *********************************************** */
+static int is_realtime_protocol(ndpi_protocol proto)
+{
+ static u_int16_t const realtime_protos[] = {
+ NDPI_PROTOCOL_YOUTUBE,
+ NDPI_PROTOCOL_YOUTUBE_UPLOAD,
+ NDPI_PROTOCOL_TIKTOK,
+ NDPI_PROTOCOL_GOOGLE,
+ NDPI_PROTOCOL_GOOGLE_CLASSROOM,
+ NDPI_PROTOCOL_GOOGLE_CLOUD,
+ NDPI_PROTOCOL_GOOGLE_DOCS,
+ NDPI_PROTOCOL_GOOGLE_DRIVE,
+ NDPI_PROTOCOL_GOOGLE_MAPS,
+ NDPI_PROTOCOL_GOOGLE_SERVICES
+ };
+
+ for (u_int16_t i = 0; i < NDPI_ARRAY_LENGTH(realtime_protos); i++) {
+ if (proto.app_protocol == realtime_protos[i]
+ || proto.master_protocol == realtime_protos[i])
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static void dump_realtime_protocol(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow)
+{
+ FILE *out = results_file ? results_file : stdout;
+ char srcip[64], dstip[64];
+ char ip_proto[64], app_name[64];
+ char date[64];
+ int ret = is_realtime_protocol(flow->detected_protocol);
+ time_t firsttime = flow->first_seen_ms;
+ struct tm result;
+
+ if (ndpi_gmtime_r(&firsttime, &result) != NULL)
+ {
+ strftime(date, sizeof(date), "%d.%m.%y %H:%M:%S", &result);
+ } else {
+ snprintf(date, sizeof(date), "%s", "Unknown");
+ }
+
+ if (flow->ip_version==4) {
+ inet_ntop(AF_INET, &flow->src_ip, srcip, sizeof(srcip));
+ inet_ntop(AF_INET, &flow->dst_ip, dstip, sizeof(dstip));
+ } else {
+ snprintf(srcip, sizeof(srcip), "[%s]", flow->src_name);
+ snprintf(dstip, sizeof(dstip), "[%s]", flow->dst_name);
+ }
+
+ ndpi_protocol2name(workflow->ndpi_struct, flow->detected_protocol, app_name, sizeof(app_name));
+
+ if (ret == 1) {
+ fprintf(out, "Detected Realtime protocol %s --> [%s] %s:%d <--> %s:%d app=%s <%s>\n",
+ date, ndpi_get_ip_proto_name(flow->protocol, ip_proto, sizeof(ip_proto)),
+ srcip, ntohs(flow->src_port), dstip, ntohs(flow->dst_port),
+ app_name, flow->human_readeable_string_buffer);
+ }
+}
+
+static void on_protocol_discovered(struct ndpi_workflow * workflow,
+ struct ndpi_flow_info * flow,
+ void * userdata)
+{
+ (void)userdata;
+ dump_realtime_protocol(workflow, flow);
+}
+
+/* *********************************************** */
+
/**
* @brief Setup for detection begin
*/
@@ -2701,6 +2772,9 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
}
}
+ ndpi_workflow_set_flow_callback(ndpi_thread_info[thread_id].workflow,
+ on_protocol_discovered, NULL);
+
/* Make sure to load lists before finalizing the initialization */
ndpi_set_protocol_detection_bitmask2(ndpi_thread_info[thread_id].workflow->ndpi_struct, &enabled_bitmask);