tor_multipath_voip/src/donar.c

80 lines
2 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-13 14:32:38 +00:00
int opt, is_server, is_client, errored;
char *host, *port, *onion_file, *algo;
2019-02-11 22:40:37 +00:00
host = NULL;
port = NULL;
onion_file = NULL;
2019-02-13 14:32:38 +00:00
algo = NULL;
2019-02-11 22:40:37 +00:00
is_server = 0;
is_client = 0;
2019-02-13 14:32:38 +00:00
errored = 0;
while ((opt = getopt(argc, argv, "csh:p:o:a:")) != -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;
2019-02-13 14:32:38 +00:00
case 'a':
algo = strdup(optarg);
break;
2019-02-11 09:23:38 +00:00
default:
2019-02-13 14:32:38 +00:00
goto in_error;
2019-02-11 09:23:38 +00:00
}
}
2019-02-13 14:32:38 +00:00
if (!(is_server ^ is_client)) goto in_error;
if (algo == NULL) goto in_error;
2019-02-11 09:23:38 +00:00
struct algo_skel as;
2019-02-13 14:32:38 +00:00
init_algo(&as, algo);
2019-02-11 15:23:20 +00:00
if (is_server) {
struct donar_server_ctx ctx;
2019-02-13 14:32:38 +00:00
if (host == NULL || port == NULL) goto in_error;
2019-02-11 22:40:37 +00:00
donar_server(&ctx, &as, host, port);
2019-02-11 15:23:20 +00:00
} else if (is_client) {
struct donar_client_ctx ctx;
2019-02-13 14:32:38 +00:00
if (port == NULL || onion_file == NULL) goto in_error;
donar_client(&ctx, &as, onion_file, port);
2019-02-11 15:23:20 +00:00
}
2019-02-13 14:32:38 +00:00
goto terminate;
in_error:
errored = 1;
fprintf(stderr, "Usage as client : %s -c -a <algo> -p <udp port> -o <onion service file>\n", argv[0]);
fprintf(stderr, "Usage as server : %s -s -a <algo> -h <udp host> -p <udp port>\n\n", argv[0]);
fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, host=%s, port=%s, onion_file=%s\n",
is_client, is_server, algo, host, port, onion_file);
terminate:
if (host != NULL) free(host);
if (onion_file != NULL) free(onion_file);
if (port != NULL) free(port);
if (algo != NULL) free(algo);
2019-02-11 09:23:38 +00:00
2019-02-13 14:32:38 +00:00
return errored;
2019-02-08 13:28:39 +00:00
}