From 53186dbc4b89fbc98731c01a5cedf664223caec4 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Fri, 5 Jan 2018 21:59:39 +0100 Subject: [PATCH] parse config file --- src/include/datastorage.h | 2 ++ src/main.c | 1 + src/network/tcpsocket.c | 5 ++--- src/utils/dawn_uci.c | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 36f8cc9..3328f13 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -67,6 +67,7 @@ struct time_config_s { struct network_config_s { const char* broadcast_ip; int broadcast_port; + int tcp_port; int network_option; const char* multicast; const char* shared_key; @@ -74,6 +75,7 @@ struct network_config_s { int bool_multicast; }; +struct network_config_s network_config; struct time_config_s timeout_config; // ---------------- Global variables ---------------- diff --git a/src/main.c b/src/main.c index adb622b..79f3f93 100644 --- a/src/main.c +++ b/src/main.c @@ -113,6 +113,7 @@ int main(int argc, char **argv) { uci_init(); struct network_config_s net_config = uci_get_dawn_network(); + network_config = net_config; printf("Broadcst bla: %s\n", net_config.broadcast_ip); gcrypt_init(); diff --git a/src/network/tcpsocket.c b/src/network/tcpsocket.c index d1da2f5..ded7600 100644 --- a/src/network/tcpsocket.c +++ b/src/network/tcpsocket.c @@ -20,7 +20,6 @@ #define TRUE 1 #define FALSE 0 -#define PORT 1026 void *run_tcp_socket(void *arg) { @@ -59,14 +58,14 @@ void *run_tcp_socket(void *arg) //type of socket created address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = htons(PORT); + address.sin_port = htons(network_config.tcp_port); //bind the socket to localhost port 8888 if (bind(master_socket, (struct sockaddr *) &address, sizeof(address)) < 0) { perror("bind failed"); exit(EXIT_FAILURE); } - printf("Listener on port %d \n", PORT); + printf("Listener on port %d \n", network_config.tcp_port); //try to specify maximum of 3 pending connections for the master socket if (listen(master_socket, 3) < 0) { diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index 51106b0..35b7317 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -92,6 +92,7 @@ struct network_config_s uci_get_dawn_network() { ret.shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key"); ret.iv = uci_lookup_option_string(uci_ctx, s, "iv"); ret.network_option = uci_lookup_option_int(uci_ctx, s, "network_option"); + ret.tcp_port = uci_lookup_option_int(uci_ctx, s, "tcp_port"); return ret; } }