tor_multipath_voip/src/capreplay.c

87 lines
2.1 KiB
C
Raw Normal View History

2019-06-03 12:32:52 +00:00
#include <stdio.h>
#include <stdlib.h>
2019-06-18 15:01:37 +00:00
#include <glib-2.0/glib.h>
#include <glib-2.0/gmodule.h>
#include <glib-2.0/glib-object.h>
2019-06-03 12:32:52 +00:00
#include "cap_utils.h"
#include "net_tools.h"
2019-06-18 15:01:37 +00:00
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);
}
2019-06-03 12:32:52 +00:00
int main(int argc, char** argv) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("~ capreplay ~\n");
int opt, verbose = 0, is_active = 0;
char *outf, *inf;
while ((opt = getopt(argc, argv, "r:s:m:v")) != -1) {
switch(opt) {
case 'v':
verbose++;
break;
case 'r':
inf = optarg;
break;
case 's':
outf = optarg;
break;
case 'm':
is_active = strcmp(optarg, "active") == 0;
break;
default:
goto usage;
}
}
2019-06-18 15:01:37 +00:00
struct cap_file cf_in, cf_out;
cap_load(&cf_in, inf);
cap_load(&cf_out, outf);
2019-06-03 12:32:52 +00:00
2019-06-18 15:01:37 +00:00
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) {
2019-06-03 12:32:52 +00:00
fprintf(stderr, "No buffer packet to read\n");
exit(EXIT_FAILURE);
}
2019-06-18 15:01:37 +00:00
struct timespec started_rcv, started_snd;
2019-06-03 12:32:52 +00:00
struct buffer_packet bp;
2019-06-18 15:01:37 +00:00
// 1. init listening
// 2. check if I should start
// 3.
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");
2019-06-03 12:32:52 +00:00
2019-06-18 15:01:37 +00:00
for (int c = 0; c < nbp_in; c++) {
cap_next_bp (&cf_in, &bp);
2019-06-03 12:32:52 +00:00
//sleep(bp.seen);
// send on UDP to 127.13.3.7
// sleep for given time
//sendto(fd, bp.ip.ap.fmt.content.clear.payload);
}
return 0;
usage:
fprintf(stderr, "Usage: %s -r FILE.0 -s FILE.1 -m [active|passive] [-v]\n", argv[0]);
return 1;
}