From 96c1687a52b775b6786841d586239e071ef139c1 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 8 Sep 2013 06:45:13 +0000 Subject: [PATCH] net: makesock_addrinfo(): Make socketfd local to the loop. And rename it to fd, as there is no other file descriptor in this function. --- net.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net.c b/net.c index 822f70de..94350647 100644 --- 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) { - int ret = -E_MAKESOCK, on = 1, sockfd = -1; + int ret = -E_MAKESOCK, on = 1; for (; ai; ai = ai->ai_next) { + int fd; 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 (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; } /* @@ -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). */ - if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { - close(sockfd); + close(fd); 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; } - return sockfd; + return fd; } return -E_MAKESOCK; } -- 2.39.5