Add LocalDiscovery option which tries to detect peers on the local network.
[tinc] / src / net_setup.c
index 2301c83..bab50fe 100644 (file)
@@ -356,6 +356,7 @@ static bool setup_myself(void) {
        get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
        get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets);
        get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
+       get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
        strictsubnets |= tunnelserver;
 
        if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) {
@@ -397,8 +398,8 @@ static bool setup_myself(void) {
                myself->options |= OPTION_CLAMP_MSS;
 
        get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
-
        get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
+       get_config_bool(lookup_config(config_tree, "Broadcast"), &broadcast);
 
 #if !defined(SOL_IP) || !defined(IP_TOS)
        if(priorityinheritance)
@@ -580,6 +581,7 @@ static bool setup_myself(void) {
 
        /* Open sockets */
 
+       listen_sockets = 0;
        cfg = lookup_config(config_tree, "BindToAddress");
 
        do {
@@ -601,9 +603,12 @@ static bool setup_myself(void) {
                        return false;
                }
 
-               listen_sockets = 0;
-
                for(aip = ai; aip; aip = aip->ai_next) {
+                       if(listen_sockets >= MAXSOCKETS) {
+                               logger(LOG_ERR, "Too many listening sockets");
+                               return false;
+                       }
+
                        listen_socket[listen_sockets].tcp =
                                setup_listen_socket((sockaddr_t *) aip->ai_addr);