WIP capture traffic
This commit is contained in:
parent
b592754973
commit
7e2a7449c6
3 changed files with 35 additions and 9 deletions
|
@ -1,8 +1,21 @@
|
||||||
#include "capture_traffic.h"
|
#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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,26 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/signalfd.h>
|
#include <glib-2.0/glib.h>
|
||||||
|
#include <glib-2.0/gmodule.h>
|
||||||
|
#include <glib-2.0/glib-object.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "evt_core.h"
|
#include "evt_core.h"
|
||||||
|
|
||||||
struct capture_ctx {
|
struct captured_packet {
|
||||||
|
struct timeval* captured_time;
|
||||||
|
char* pkt;
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_traffic_capture(struct capture_ctx* ctx);
|
struct capture_ctx {
|
||||||
void stop_traffic_capture(struct capture_ctx* 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);
|
||||||
|
|
|
@ -166,7 +166,7 @@ void algo_main_destroy(void* app_ctx) {
|
||||||
ctx->ref_count--;
|
ctx->ref_count--;
|
||||||
if (ctx->ref_count > 0) return;
|
if (ctx->ref_count > 0) return;
|
||||||
|
|
||||||
stop_traffic_capture(&ctx->cap);
|
traffic_capture_stop(&ctx->cap);
|
||||||
destroy_buffer_management(&ctx->br);
|
destroy_buffer_management(&ctx->br);
|
||||||
if (ctx->free_misc) ctx->free_misc(ctx->misc);
|
if (ctx->free_misc) ctx->free_misc(ctx->misc);
|
||||||
free(ctx);
|
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);
|
evt_core_add_cat(evt, &udp_write);
|
||||||
|
|
||||||
init_buffer_management(&ctx->br);
|
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++) {
|
for (int i = 0; i < sizeof(available_algo) / sizeof(available_algo[0]); i++) {
|
||||||
if (strcmp(available_algo[i].name, ap->algo_name) == 0) {
|
if (strcmp(available_algo[i].name, ap->algo_name) == 0) {
|
||||||
|
|
Loading…
Reference in a new issue