From 7e2a7449c6ba7d9c5bec7bf256f75002441a1ec1 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 27 May 2019 18:14:21 +0200 Subject: [PATCH] WIP capture traffic --- src/capture_traffic.c | 17 +++++++++++++++-- src/capture_traffic.h | 23 ++++++++++++++++++----- src/proxy.c | 4 ++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/capture_traffic.c b/src/capture_traffic.c index c431e8c..a5ab0fa 100644 --- a/src/capture_traffic.c +++ b/src/capture_traffic.c @@ -1,8 +1,21 @@ #include "capture_traffic.h" -void init_traffic_capture(struct capture_ctx* ctx) { +void traffic_capture_init(struct capture_ctx* ctx, char* filename) { + ctx->activated = filename == NULL ? 0 : 1; + if (!ctx->activated) return; + ctx->filename = strdup(filename); + ctx->capture_in = g_queue_new (); + ctx->capture_out = g_queue_new (); } -void stop_traffic_capture(struct capture_ctx* ctx) { +void traffic_capture_stop(struct capture_ctx* ctx) { + if (!ctx->activated) return; + FILE* fd = NULL; + + if ((fd = fopen(ctx->filename, "w")) == NULL) { + + } + + free(ctx->filename); } diff --git a/src/capture_traffic.h b/src/capture_traffic.h index 7024248..6210b14 100644 --- a/src/capture_traffic.h +++ b/src/capture_traffic.h @@ -2,13 +2,26 @@ #include #include #include -#include +#include +#include +#include #include #include "evt_core.h" -struct capture_ctx { - +struct captured_packet { + struct timeval* captured_time; + char* pkt; }; -void init_traffic_capture(struct capture_ctx* ctx); -void stop_traffic_capture(struct capture_ctx* ctx); +struct capture_ctx { + uint8_t activated; + char* filename; + struct timeval* start_time; + GQueue* capture_in; + GQueue* capture_out; +}; + +void traffic_capture_init(struct capture_ctx* ctx, char* filename); +void traffic_capture_stop(struct capture_ctx* ctx); +void traffic_capture_notify_in(struct capture_ctx* ctx); +void traffic_capture_notify_out(struct capture_ctx* ctx); diff --git a/src/proxy.c b/src/proxy.c index d918700..45df7bf 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -166,7 +166,7 @@ void algo_main_destroy(void* app_ctx) { ctx->ref_count--; if (ctx->ref_count > 0) return; - stop_traffic_capture(&ctx->cap); + traffic_capture_stop(&ctx->cap); destroy_buffer_management(&ctx->br); if (ctx->free_misc) ctx->free_misc(ctx->misc); free(ctx); @@ -236,7 +236,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) { evt_core_add_cat(evt, &udp_write); init_buffer_management(&ctx->br); - init_traffic_capture(&ctx->cap); + traffic_capture_init(&ctx->cap, ap->capture_file); for (int i = 0; i < sizeof(available_algo) / sizeof(available_algo[0]); i++) { if (strcmp(available_algo[i].name, ap->algo_name) == 0) {