From f05477cd56c4a87969f4d9d68ccedd9ad56df3b8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 18 Jun 2019 17:01:37 +0200 Subject: [PATCH] WIP cap replay --- src/cap_utils.c | 3 +++ src/cap_utils.h | 1 + src/capreplay.c | 46 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/cap_utils.c b/src/cap_utils.c index 4a21f4a..4d3724c 100644 --- a/src/cap_utils.c +++ b/src/cap_utils.c @@ -38,3 +38,6 @@ size_t cap_count_bp(struct cap_file *cf) { void cap_unload(struct cap_file *cf) { fclose(cf->fd); } +void cap_begin(struct cap_file *cf) { + fseek(cf->fd, 0L, SEEK_SET); +} diff --git a/src/cap_utils.h b/src/cap_utils.h index e4ea634..0c97f6e 100644 --- a/src/cap_utils.h +++ b/src/cap_utils.h @@ -16,4 +16,5 @@ void cap_next_bp(struct cap_file *cf, struct buffer_packet* bp); void cap_peek_bp(struct cap_file *cf, struct buffer_packet* bp); void cap_npeek_bp(struct cap_file *cf, int c, struct buffer_packet* bp); size_t cap_count_bp(struct cap_file *cf); +void cap_begin(struct cap_file *cf); void cap_unload(struct cap_file *cf); diff --git a/src/capreplay.c b/src/capreplay.c index fdec439..d84873f 100644 --- a/src/capreplay.c +++ b/src/capreplay.c @@ -1,8 +1,21 @@ #include #include +#include +#include +#include #include "cap_utils.h" #include "net_tools.h" +void get_ports(struct cap_file *cf) { + struct buffer_packet bp; + size_t entry_count = cap_count_bp (cf); + for (int c = 0; c < entry_count; c++) { + cap_next_bp (cf, &bp); + int a = bp.ip.ap.fmt.content.clear.port; + } + cap_begin(cf); +} + int main(int argc, char** argv) { setvbuf(stdout, NULL, _IONBF, 0); printf("~ capreplay ~\n"); @@ -28,24 +41,37 @@ int main(int argc, char** argv) { } } - struct cap_file cf; - cap_load(&cf, inf); + struct cap_file cf_in, cf_out; + cap_load(&cf_in, inf); + cap_load(&cf_out, outf); - size_t nbp = cap_count_bp (&cf); - if (nbp < 1) { + size_t nbp_in = cap_count_bp (&cf_in); + size_t nbp_out = cap_count_bp (&cf_out); + if (nbp_in < 1 || nbp_out < 1) { fprintf(stderr, "No buffer packet to read\n"); exit(EXIT_FAILURE); } - struct timespec started; + struct timespec started_rcv, started_snd; struct buffer_packet bp; - cap_peek_bp (&cf, &bp); - started = bp.seen; - int fd = create_udp_client ("127.0.0.1", "5000"); + // 1. init listening + // 2. check if I should start + // 3. - for (int c = 0; c < nbp; c++) { - cap_next_bp (&cf, &bp); + cap_peek_bp (&cf_in, &bp); started_rcv = bp.seen; + cap_peek_bp (&cf_out, &bp); started_snd = bp.seen; + if (started_rcv.tv_sec < started_snd.tv_sec || + (started_rcv.tv_sec == started_snd.tv_sec && started_rcv.tv_nsec < started_snd.tv_nsec)) { + // We need to wait to receive some packets before emitting as we are a server + } else { + // We are a client and we must emit packets now + } + + //int fd = create_udp_client ("127.0.0.1", "5000"); + + for (int c = 0; c < nbp_in; c++) { + cap_next_bp (&cf_in, &bp); //sleep(bp.seen); // send on UDP to 127.13.3.7 // sleep for given time