tor_multipath_voip/src/donar.c

73 lines
1.8 KiB
C
Raw Normal View History

2019-02-08 13:28:39 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
2019-02-11 21:40:00 +00:00
#include "algo_skel.h"
2019-02-11 09:23:38 +00:00
#include "donar_client.h"
#include "donar_server.h"
2019-02-08 13:28:39 +00:00
int main(int argc, char** argv) {
printf("~ Donar ~\n");
2019-02-11 09:23:38 +00:00
2019-02-11 22:40:37 +00:00
int opt, is_server, is_client;
char *host, *port, *onion_file;
host = NULL;
port = NULL;
onion_file = NULL;
is_server = 0;
is_client = 0;
while ((opt = getopt(argc, argv, "csh:p:o:")) != -1) {
2019-02-11 09:23:38 +00:00
switch(opt) {
case 's':
is_server = 1;
break;
2019-02-11 22:40:37 +00:00
case 'h':
host = strdup(optarg);
break;
case 'p':
port = strdup(optarg);
break;
case 'o':
onion_file = strdup(optarg);
break;
2019-02-11 09:23:38 +00:00
case 'c':
is_client = 1;
break;
default:
2019-02-11 22:40:37 +00:00
fprintf(stderr, "Usage: %s [-c -p <udp port> -o <onion service file> | -s -h <udp host> -p <udp port>]\n", argv[0]);
2019-02-11 09:23:38 +00:00
exit(EXIT_FAILURE);
}
}
if (!(is_server ^ is_client)) {
2019-02-11 22:40:37 +00:00
fprintf(stderr, "You need to choose between client and server\n");
2019-02-11 09:23:38 +00:00
exit(EXIT_FAILURE);
}
struct algo_skel as;
algo_naive (&as);
2019-02-11 15:23:20 +00:00
if (is_server) {
struct donar_server_ctx ctx;
2019-02-11 22:40:37 +00:00
if (host == NULL || port == NULL) {
fprintf(stderr, "You need to set a host -h and a port -p\n");
exit(EXIT_FAILURE);
}
printf("params: %s:%s\n", host, port);
donar_server(&ctx, &as, host, port);
2019-02-11 15:23:20 +00:00
} else if (is_client) {
struct donar_client_ctx ctx;
if (port == NULL || onion_file == NULL) {
fprintf(stderr, "You need to set an onion_file -o and a port -p\n");
exit(EXIT_FAILURE);
}
donar_client(&ctx, &as, onion_file, port);
2019-02-11 15:23:20 +00:00
}
2019-02-11 09:23:38 +00:00
2019-02-11 22:40:37 +00:00
free(onion_file);
free(port);
free(host);
2019-02-11 09:23:38 +00:00
return 0;
2019-02-08 13:28:39 +00:00
}