X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnet.c;h=304c62683b4e5faa2c50a3f675ad47051258ee57;hb=2f9ce0a8f244306d8d5bc6a44963c73c0d9fae73;hp=7c600534e3a682488200bbfa9f4cf320e7fe11f3;hpb=529b8fab8c21e7ae5af91d742ff202eab38e51f3;p=meshlink diff --git a/src/net.c b/src/net.c index 7c600534..304c6268 100644 --- a/src/net.c +++ b/src/net.c @@ -639,11 +639,6 @@ void retry(meshlink_handle_t *mesh) { }); } -#ifdef HAVE_IFADDRS_H - struct ifaddrs *ifa = NULL; - getifaddrs(&ifa); -#endif - /* For active connections, check if their addresses are still valid. * If yes, reset their ping timers, otherwise terminate them. */ for list_each(connection_t, c, mesh->connections) { @@ -655,12 +650,6 @@ void retry(meshlink_handle_t *mesh) { c->last_ping_time = 0; } -#ifdef HAVE_IFADDRS_H - - if(!ifa) { - continue; - } - sockaddr_t sa; socklen_t salen = sizeof(sa); @@ -668,32 +657,33 @@ void retry(meshlink_handle_t *mesh) { continue; } - bool found = false; + switch(sa.sa.sa_family) { + case AF_INET: + sa.in.sin_port = 0; + break; - for(struct ifaddrs *ifap = ifa; ifap; ifap = ifap->ifa_next) { - if(ifap->ifa_addr && !sockaddrcmp_noport(&sa, (sockaddr_t *)ifap->ifa_addr)) { - found = true; - break; - } + case AF_INET6: + sa.in6.sin6_port = 0; + break; + + default: + continue; + } + + int sock = socket(sa.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); + if(sock != -1) { + continue; } - if(!found) { + if(bind(sock, &sa.sa, salen) && errno == EADDRNOTAVAIL) { logger(mesh, MESHLINK_DEBUG, "Local address for connection to %s no longer valid, terminating", c->name); terminate_connection(mesh, c, c->status.active); } -#endif + closesocket(sock); } -#ifdef HAVE_IFADDRS_H - - if(ifa) { - freeifaddrs(ifa); - } - -#endif - /* Kick the ping timeout handler */ timeout_set(&mesh->loop, &mesh->pingtimer, &(struct timeval) { 0, 0