From 0d79f476e0311fb36f41c9c6d86744f9d5386fba Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 12 Mar 2020 21:32:41 +0100 Subject: [PATCH] Use slashes internally to separate hostnames and ports in invitation addresses. This avoids possible confusion when an IPv6 hostname is used without an explicit port number. --- src/meshlink.c | 10 +++++----- test/invite-join.c | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index e7e7d5c8..ab3ab7ff 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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); } diff --git a/test/invite-join.c b/test/invite-join.c index 0bb09b0b..e3f85ed6 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -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); -- 2.39.5