parse config file

This commit is contained in:
PolynomialDivision 2018-01-05 21:59:39 +01:00
parent 7508faae91
commit 53186dbc4b
4 changed files with 6 additions and 3 deletions

View file

@ -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 ----------------

View file

@ -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();

View file

@ -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) {

View file

@ -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;
}
}