X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=789121d13afbec89a2d56bdf4737cadc19ee2cac;hb=fbcf089;hp=0090d54ddeadc49c9d6e16646a00af17ae07fd4c;hpb=3febbb4453f5c6b0286e7e3c68a5dbcec975b6fd;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 0090d54d..789121d1 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -446,7 +446,7 @@ static char *get_my_hostname(meshlink_handle_t *mesh, uint32_t flags) { if(colon) { *colon = 0; - port[n] = colon + 1; + port[n] = xstrdup(colon + 1); } n++; @@ -482,7 +482,7 @@ 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); @@ -492,7 +492,7 @@ static char *get_my_hostname(meshlink_handle_t *mesh, uint32_t flags) { remove_duplicate_hostnames(hostname, port, 4); // 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; } @@ -639,7 +641,7 @@ static bool try_bind(int port) { return success; } -static int check_port(meshlink_handle_t *mesh) { +int check_port(meshlink_handle_t *mesh) { for(int i = 0; i < 1000; i++) { int port = 0x1000 + prng(mesh, 0x8000);