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-15 17:09:51 +00:00
|
|
|
#include <gmodule.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) {
|
2019-03-06 15:39:39 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
2019-02-08 13:28:39 +00:00
|
|
|
printf("~ Donar ~\n");
|
2019-02-11 09:23:38 +00:00
|
|
|
|
2019-04-01 14:05:36 +00:00
|
|
|
struct donar_params dp = {0};
|
2019-03-28 10:47:14 +00:00
|
|
|
donar_init_params (&dp);
|
2019-02-13 14:32:38 +00:00
|
|
|
|
2019-09-06 13:28:42 +00:00
|
|
|
while ((dp.opt = getopt(argc, argv, "nvcse:r:o:a:bl:d:f:i:p:")) != -1) {
|
2019-03-28 10:47:14 +00:00
|
|
|
switch(dp.opt) {
|
2019-09-04 14:40:02 +00:00
|
|
|
case 'n':
|
|
|
|
dp.tof |= TOR_ONION_FLAG_NON_ANONYMOUS;
|
|
|
|
break;
|
2019-04-01 12:16:41 +00:00
|
|
|
case 'v':
|
|
|
|
dp.verbose++;
|
|
|
|
break;
|
2019-02-11 09:23:38 +00:00
|
|
|
case 's':
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.is_server = 1;
|
2019-02-11 09:23:38 +00:00
|
|
|
break;
|
2019-02-19 18:15:37 +00:00
|
|
|
case 'e':
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.port = strdup(optarg);
|
|
|
|
if (dp.port == NULL) goto terminate;
|
|
|
|
g_ptr_array_add (dp.exposed_ports, dp.port);
|
2019-02-19 18:15:37 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.port = strdup(optarg);
|
|
|
|
if (dp.port == NULL) goto terminate;
|
|
|
|
g_ptr_array_add (dp.remote_ports, dp.port);
|
2019-02-11 22:40:37 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.onion_file = strdup(optarg);
|
2019-02-11 22:40:37 +00:00
|
|
|
break;
|
2019-02-11 09:23:38 +00:00
|
|
|
case 'c':
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.is_client = 1;
|
2019-02-11 09:23:38 +00:00
|
|
|
break;
|
2019-02-13 14:32:38 +00:00
|
|
|
case 'a':
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.algo = strdup(optarg);
|
|
|
|
break;
|
2019-09-06 13:28:42 +00:00
|
|
|
case 'p':
|
|
|
|
dp.algo_specific_params = strdup(optarg);
|
2019-03-28 10:47:14 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
dp.is_waiting_bootstrap = 1;
|
2019-02-13 14:32:38 +00:00
|
|
|
break;
|
2019-05-09 13:33:27 +00:00
|
|
|
case 'l':
|
|
|
|
dp.links = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
sscanf(optarg, "%d,%d", &dp.fresh_data, &dp.redundant_data);
|
|
|
|
break;
|
2019-06-21 14:50:49 +00:00
|
|
|
case 'i':
|
|
|
|
dp.bound_ip = strdup(optarg);
|
|
|
|
break;
|
2019-05-27 15:32:00 +00:00
|
|
|
case 'f':
|
|
|
|
dp.capture_file = 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-03-28 10:47:14 +00:00
|
|
|
if (!(dp.is_server ^ dp.is_client)) goto in_error;
|
|
|
|
if (dp.algo == NULL) goto in_error;
|
2019-06-21 14:50:49 +00:00
|
|
|
if (dp.bound_ip == NULL) dp.bound_ip = strdup("127.0.0.1");
|
2019-02-11 09:23:38 +00:00
|
|
|
|
2019-03-28 10:47:14 +00:00
|
|
|
if (dp.is_server) {
|
2019-02-11 15:23:20 +00:00
|
|
|
struct donar_server_ctx ctx;
|
2019-03-28 10:47:14 +00:00
|
|
|
if (dp.exposed_ports->len < 1 && dp.remote_ports->len < 1) goto in_error;
|
|
|
|
donar_server(&ctx, &dp);
|
|
|
|
} else if (dp.is_client) {
|
2019-02-12 19:33:12 +00:00
|
|
|
struct donar_client_ctx ctx;
|
2019-03-28 10:47:14 +00:00
|
|
|
if ((dp.exposed_ports->len < 1 && dp.remote_ports->len < 1) || dp.onion_file == NULL) goto in_error;
|
|
|
|
donar_client(&ctx, &dp);
|
2019-02-11 15:23:20 +00:00
|
|
|
}
|
2019-02-13 14:32:38 +00:00
|
|
|
goto terminate;
|
|
|
|
|
|
|
|
in_error:
|
2019-03-28 10:47:14 +00:00
|
|
|
dp.errored = 1;
|
2019-06-21 14:50:49 +00:00
|
|
|
fprintf(stderr, "Usage as client : %s -c -a <algo> -o <onion service file> [-h] [-b] [-i <bound ip>] [-f <dump packets>] [-l <links>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n", argv[0]);
|
2019-09-04 14:40:02 +00:00
|
|
|
fprintf(stderr, "Usage as server : %s -s -a <algo> [-h] [-b] [-n] [-i <bound ip>] [-l <links>] [-f <dump_packets>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n\n", argv[0]);
|
2019-05-09 17:53:47 +00:00
|
|
|
fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, exposed_ports=%d, remote_ports=%d, onion_file=%s, links=%d, duplication=%d,%d\n",
|
|
|
|
dp.is_client, dp.is_server, dp.algo, dp.exposed_ports->len, dp.remote_ports->len, dp.onion_file, dp.links, dp.fresh_data, dp.redundant_data);
|
2019-02-13 14:32:38 +00:00
|
|
|
|
|
|
|
terminate:
|
2019-06-21 14:50:49 +00:00
|
|
|
// @FIXME: Should be refactored in free_donar_params()
|
2019-03-28 10:47:14 +00:00
|
|
|
if (dp.onion_file != NULL) free(dp.onion_file);
|
|
|
|
if (dp.algo != NULL) free(dp.algo);
|
2019-05-27 15:32:00 +00:00
|
|
|
if (dp.capture_file != NULL) free(dp.capture_file);
|
2019-06-21 14:50:49 +00:00
|
|
|
if (dp.bound_ip != NULL) free(dp.bound_ip);
|
2019-09-06 13:28:42 +00:00
|
|
|
if (dp.algo_specific_params != NULL) free(dp.algo_specific_params);
|
2019-05-27 15:32:00 +00:00
|
|
|
|
2019-03-28 10:47:14 +00:00
|
|
|
g_ptr_array_free(dp.exposed_ports, TRUE);
|
|
|
|
g_ptr_array_free(dp.remote_ports, TRUE);
|
2019-02-11 09:23:38 +00:00
|
|
|
|
2019-03-28 10:47:14 +00:00
|
|
|
return dp.errored;
|
2019-02-08 13:28:39 +00:00
|
|
|
}
|