From: Lakshminarayana Gurram <38289425+lakshminarayanagurram@users.noreply.github.com> Date: Fri, 8 Mar 2019 05:10:59 +0000 (+0530) Subject: Fix NULL checking of addrinfo structure in try_bind function X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=026aa799bdccd860575e4ce228b750f47abd31e2;p=meshlink Fix NULL checking of addrinfo structure in try_bind function --- diff --git a/src/meshlink.c b/src/meshlink.c index 6f83c22f..9faccff4 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -626,23 +626,22 @@ static bool try_bind(int port) { return false; } - while(ai) { - int fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP); + //while(ai) { + for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) { + int fd = socket(aip->ai_family, SOCK_STREAM, IPPROTO_TCP); if(!fd) { freeaddrinfo(ai); return false; } - int result = bind(fd, ai->ai_addr, ai->ai_addrlen); + int result = bind(fd, aip->ai_addr, aip->ai_addrlen); closesocket(fd); if(result) { freeaddrinfo(ai); return false; } - - ai = ai->ai_next; } freeaddrinfo(ai);