X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=9435064715cd368ac6bc04e3dbac0b4c3d0b3e69;hp=822f70def6aee8f6cf6e202832ab02c4553628b8;hb=96c1687a52b775b6786841d586239e071ef139c1;hpb=6ac9ff30a69753606cc76913515ae34f5ce2868d 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; }