net: makesock_addrinfo(): Make socketfd local to the loop.
authorAndre Noll <maan@systemlinux.org>
Sun, 8 Sep 2013 06:45:13 +0000 (06:45 +0000)
committerAndre Noll <maan@systemlinux.org>
Wed, 1 Jan 2014 17:50:02 +0000 (17:50 +0000)
And rename it to fd, as there is no other file descriptor in this
function.

net.c

diff --git a/net.c b/net.c
index 822f70d..9435064 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;
 }