WIP cap replay

This commit is contained in:
Quentin 2019-06-18 17:01:37 +02:00
parent a822707158
commit f05477cd56
3 changed files with 40 additions and 10 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -1,8 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <glib-2.0/glib.h>
#include <glib-2.0/gmodule.h>
#include <glib-2.0/glib-object.h>
#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