]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Use slashes internally to separate hostnames and ports in invitation addresses.
[meshlink] / src / meshlink.c
index 6e7cda60a3f71fd1a94424c754af48a1288ae0c5..ab3ab7ff9be3d4a2352760d9c56bbc5908f45443 100644 (file)
@@ -442,11 +442,11 @@ static char *get_my_hostname(meshlink_handle_t *mesh, uint32_t flags) {
        if(mesh->invitation_addresses) {
                for list_each(char, combo, mesh->invitation_addresses) {
                        hostname[n] = xstrdup(combo);
-                       char *colon = strchr(hostname[n], ':');
+                       char *slash = strrchr(hostname[n], '/');
 
-                       if(colon) {
-                               *colon = 0;
-                               port[n] = xstrdup(colon + 1);
+                       if(slash) {
+                               *slash = 0;
+                               port[n] = xstrdup(slash + 1);
                        }
 
                        n++;
@@ -482,17 +482,17 @@ static char *get_my_hostname(meshlink_handle_t *mesh, uint32_t flags) {
                }
        }
 
-       for(int i = 0; i < 4; i++) {
+       for(int i = 0; i < n; i++) {
                // Ensure we always have a port number
                if(hostname[i] && !port[i]) {
                        port[i] = xstrdup(mesh->myport);
                }
        }
 
-       remove_duplicate_hostnames(hostname, port, 4);
+       remove_duplicate_hostnames(hostname, port, n);
 
        // Resolve the hostnames
-       for(int i = 0; i < 4; i++) {
+       for(int i = 0; i < n; i++) {
                if(!hostname[i]) {
                        continue;
                }
@@ -510,8 +510,10 @@ static char *get_my_hostname(meshlink_handle_t *mesh, uint32_t flags) {
                        continue;
                }
 
-               // Remember the address
-               node_add_recent_address(mesh, mesh->self, (sockaddr_t *)ai_in->ai_addr);
+               // Remember the address(es)
+               for(struct addrinfo *aip = ai_in; aip; aip = aip->ai_next) {
+                       node_add_recent_address(mesh, mesh->self, (sockaddr_t *)aip->ai_addr);
+               }
 
                if(flags & MESHLINK_INVITE_NUMERIC) {
                        // We don't need to do any further conversion
@@ -554,10 +556,10 @@ static char *get_my_hostname(meshlink_handle_t *mesh, uint32_t flags) {
        }
 
        // Remove duplicates again, since IPv4 and IPv6 addresses might map to the same hostname
-       remove_duplicate_hostnames(hostname, port, 4);
+       remove_duplicate_hostnames(hostname, port, n);
 
        // Concatenate all unique address to the hostport string
-       for(int i = 0; i < 4; i++) {
+       for(int i = 0; i < n; i++) {
                if(!hostname[i]) {
                        continue;
                }
@@ -2467,11 +2469,7 @@ bool meshlink_add_invitation_address(struct meshlink_handle *mesh, const char *a
        char *combo;
 
        if(port) {
-               if(strchr(address, ':')) {
-                       xasprintf(&combo, "[%s]:%s", address, port);
-               } else {
-                       xasprintf(&combo, "%s:%s", address, port);
-               }
+               xasprintf(&combo, "%s/%s", address, port);
        } else {
                combo = xstrdup(address);
        }