]> git.meshlink.io Git - meshlink/blobdiff - src/net_setup.c
Automatically configure and compile catta.
[meshlink] / src / net_setup.c
index b02dbd14d246d87164843ac6a4011ddf45c3e8f2..96be9df37d87b6be2610436cf845e5c1ec32b2cb 100644 (file)
@@ -82,7 +82,7 @@ bool read_ecdsa_private_key(meshlink_handle_t *mesh) {
        FILE *fp;
        char filename[PATH_MAX];
 
-       snprintf(filename,PATH_MAX, "%s" SLASH "ecdsa_key.priv", mesh->confbase);
+       snprintf(filename, PATH_MAX, "%s" SLASH "ecdsa_key.priv", mesh->confbase);
        fp = fopen(filename, "rb");
 
        if(!fp) {
@@ -108,7 +108,7 @@ static bool read_invitation_key(meshlink_handle_t *mesh) {
                mesh->invitation_key = NULL;
        }
 
-       snprintf(filename,PATH_MAX, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", mesh->confbase);
+       snprintf(filename, PATH_MAX, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", mesh->confbase);
 
        fp = fopen(filename, "rb");
 
@@ -157,7 +157,7 @@ bool node_write_devclass(meshlink_handle_t *mesh, node_t *n) {
        // ignore read errors; in case the file does not exist we will create it
        read_host_config(mesh, config_tree, n->name);
 
-       config_tcnf = lookup_config(config_tree, "DeviceClass");
+       config_t *cnf = lookup_config(config_tree, "DeviceClass");
 
        if(!cnf) {
                cnf = new_config();
@@ -182,7 +182,7 @@ void load_all_nodes(meshlink_handle_t *mesh) {
        struct dirent *ent;
        char dname[PATH_MAX];
 
-       snprintf(dname,PATH_MAX, "%s" SLASH "hosts", mesh->confbase);
+       snprintf(dname, PATH_MAX, "%s" SLASH "hosts", mesh->confbase);
        dir = opendir(dname);
        if(!dir) {
                logger(mesh, MESHLINK_ERROR, "Could not open %s: %s", dname, strerror(errno));
@@ -266,6 +266,8 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind
                return false;
        }
 
+       bool success = false;
+
        for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
                // Ignore duplicate addresses
                bool found = false;
@@ -308,10 +310,11 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind
                mesh->listen_socket[mesh->listen_sockets].bindto = bindto;
                memcpy(&mesh->listen_socket[mesh->listen_sockets].sa, aip->ai_addr, aip->ai_addrlen);
                mesh->listen_sockets++;
+               success = true;
        }
 
        freeaddrinfo(ai);
-       return true;
+       return success;
 }
 
 /*
@@ -389,8 +392,8 @@ bool setup_myself(meshlink_handle_t *mesh) {
        mesh->listen_sockets = 0;
 
        if(!add_listen_address(mesh, address, NULL)) {
-               if(!strcmp(mesh->myport, "0")) {
-                       logger(mesh, MESHLINK_WARNING, "Could not bind to port %s, asking OS to choose one for us", mesh->myport);
+               if(strcmp(mesh->myport, "0")) {
+                       logger(mesh, MESHLINK_INFO, "Could not bind to port %s, asking OS to choose one for us", mesh->myport);
                        free(mesh->myport);
                        mesh->myport = strdup("0");
                        if(!mesh->myport)
@@ -406,9 +409,6 @@ bool setup_myself(meshlink_handle_t *mesh) {
                return false;
        }
 
-       xasprintf(&mesh->self->hostname, "MYSELF port %s", mesh->myport);
-       mesh->self->connection->hostname = xstrdup(mesh->self->hostname);
-
        /* Done. */
 
        mesh->last_config_check = mesh->loop.now.tv_sec;