Rework files, add getopt

This commit is contained in:
Quentin Dufour 2019-02-11 10:23:38 +01:00
parent 81aac5259f
commit 13064c5ad7
6 changed files with 78 additions and 8 deletions

View file

@ -11,9 +11,13 @@ list(APPEND CSOURCES
src/tor_os.c
src/tor_ctl.h
src/tor_ctl.c
src/donar_client.h
src/donar_client.c
src/donar_server.h
src/donar_server.c
)
add_executable(donar-proxy ${CSOURCES} src/donar-proxy.c)
add_executable(donar-proxy ${CSOURCES} src/donar_proxy.c)
install(TARGETS donar-proxy
RUNTIME DESTINATION bin

0
src/donar_client.c Normal file
View file

4
src/donar_client.h Normal file
View file

@ -0,0 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
void donar_client();

View file

@ -2,17 +2,38 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <string.h>
#include "socks5.h"
#include "tor_os.h"
#include "tor_ctl.h"
#include "donar_client.h"
#include "donar_server.h"
int main(int argc, char** argv) {
printf("~ Donar ~\n");
int opt, is_server, is_client = 0;
while ((opt = getopt(argc, argv, "cs")) != -1) {
switch(opt) {
case 's':
is_server = 1;
break;
case 'c':
is_client = 1;
break;
default:
fprintf(stderr, "Usage: %s [-c | -s]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
if (!(is_server ^ is_client)) {
fprintf(stderr, "2Usage: %s [-c | -s]\n", argv[0]);
exit(EXIT_FAILURE);
}
if (is_server) donar_server();
else if (is_client) donar_client();
return 0;
/*
int sock;
struct tor_os_str tos;
@ -60,4 +81,5 @@ int main(int argc, char** argv) {
close(sock);
exit(EXIT_SUCCESS);
*/
}

33
src/donar_server.c Normal file
View file

@ -0,0 +1,33 @@
#include "donar_server.h"
void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, int* ports, int ports_count) {
tor_os_create (tos, "onion_services.pub", "onion_services.txt", ports_count);
tor_os_read (tos);
int err = 0;
err = tor_ctl_connect (tctl, "127.0.0.1", "9051");
if (err < 0) {
fprintf(stderr, "Unable to open Tor Socket\n");
exit(EXIT_FAILURE);
}
err = tor_ctl_add_onion (tctl, tos, ports);
if (err != 0) {
fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err);
exit(EXIT_FAILURE);
}
}
void destroy_resources(struct tor_os_str* tos, struct tor_ctl* tctl) {
tor_ctl_close (tctl);
tor_os_free (tos);
}
void donar_server() {
struct tor_os_str tos;
struct tor_ctl tctl = {};
int ports[10] = { 7500, 7501, 7502, 7503, 7504, 7505, 7506, 7507, 7508, 7509};
create_onion_services (&tos, &tctl, ports, 10);
printf("Onion services created\n");
destroy_resources (&tos, &tctl);
}

7
src/donar_server.h Normal file
View file

@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "socks5.h"
#include "tor_os.h"
#include "tor_ctl.h"
void donar_server();