]> git.meshlink.io Git - meshlink/commitdiff
Use slashes internally to separate hostnames and ports in invitation addresses.
authorGuus Sliepen <guus@meshlink.io>
Thu, 12 Mar 2020 20:32:41 +0000 (21:32 +0100)
committerGuus Sliepen <guus@meshlink.io>
Thu, 12 Mar 2020 20:32:41 +0000 (21:32 +0100)
This avoids possible confusion when an IPv6 hostname is used without an
explicit port number.

src/meshlink.c
test/invite-join.c

index e7e7d5c80a1adeca69e662c4ec43063e4ab6ec46..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 = strrchr(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++;
@@ -2469,7 +2469,7 @@ bool meshlink_add_invitation_address(struct meshlink_handle *mesh, const char *a
        char *combo;
 
        if(port) {
-               xasprintf(&combo, "%s:%s", address, port);
+               xasprintf(&combo, "%s/%s", address, port);
        } else {
                combo = xstrdup(address);
        }
index 0bb09b0b7ab80a15f45087347fe0020cb69c7333..e3f85ed69a09569780b01a977fba402d7cd9d9d8 100644 (file)
@@ -154,17 +154,16 @@ int main() {
        // Check that resetting and adding multiple, different invitation address works
 
        meshlink_clear_invitation_addresses(mesh1);
-       assert(meshlink_add_invitation_address(mesh1, "1.invalid.", NULL));
+       assert(meshlink_add_invitation_address(mesh1, "1.invalid.", "12345"));
        assert(meshlink_add_invitation_address(mesh1, "2.invalid.", NULL));
        assert(meshlink_add_invitation_address(mesh1, "3.invalid.", NULL));
        assert(meshlink_add_invitation_address(mesh1, "4.invalid.", NULL));
        assert(meshlink_add_invitation_address(mesh1, "5.invalid.", NULL));
        char *grault_url = meshlink_invite(mesh1, NULL, "grault");
        assert(grault_url);
-       fprintf(stderr, "%s\n", grault_url);
        localhost = strstr(grault_url, "localhost");
        assert(localhost);
-       char *invalid1 = strstr(grault_url, "1.invalid.");
+       char *invalid1 = strstr(grault_url, "1.invalid.:12345");
        assert(invalid1);
        char *invalid5 = strstr(grault_url, "5.invalid.");
        assert(invalid5);