]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - net.c
net: makesock_addrinfo(): Make socketfd local to the loop.
[paraslash.git] / net.c
diff --git a/net.c b/net.c
index 822f70def6aee8f6cf6e202832ab02c4553628b8..9435064715cd368ac6bc04e3dbac0b4c3d0b3e69 100644 (file)
--- a/net.c
+++ b/net.c
@@ -422,18 +422,19 @@ static int lookup_address(unsigned l4type, bool passive, const char *host,
 static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                struct flowopts *fo)
 {
 static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                struct flowopts *fo)
 {
-       int ret = -E_MAKESOCK, on = 1, sockfd = -1;
+       int ret = -E_MAKESOCK, on = 1;
 
        for (; ai; ai = ai->ai_next) {
 
        for (; ai; ai = ai->ai_next) {
+               int fd;
                ret = socket(ai->ai_family, sock_type(l4type), l4type);
                if (ret < 0)
                        continue;
                ret = socket(ai->ai_family, sock_type(l4type), l4type);
                if (ret < 0)
                        continue;
-               sockfd = ret;
-               flowopt_setopts(sockfd, fo);
+               fd = ret;
+               flowopt_setopts(fd, fo);
                if (!passive) {
                if (!passive) {
-                       if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
-                               return sockfd;
-                       close(sockfd);
+                       if (connect(fd, ai->ai_addr, ai->ai_addrlen) == 0)
+                               return fd;
+                       close(fd);
                        continue;
                }
                /*
                        continue;
                }
                /*
@@ -441,16 +442,16 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                 * restart (protocols using listen()) and when creating
                 * multiple listener instances (UDP multicast).
                 */
                 * restart (protocols using listen()) and when creating
                 * multiple listener instances (UDP multicast).
                 */
-               if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on,
+               if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
                                sizeof(on)) == -1) {
                                sizeof(on)) == -1) {
-                       close(sockfd);
+                       close(fd);
                        continue;
                }
                        continue;
                }
-               if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
-                       close(sockfd);
+               if (bind(fd, ai->ai_addr, ai->ai_addrlen) < 0) {
+                       close(fd);
                        continue;
                }
                        continue;
                }
-               return sockfd;
+               return fd;
        }
        return -E_MAKESOCK;
 }
        }
        return -E_MAKESOCK;
 }