X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=dfbbc1ee6b6135d74eb72fda7857f21843cdda81;hp=205041fdaec3881c4196d3d7bada084036fea3bf;hb=88bdd8c140222998d4ec31812cbf8ef108baa910;hpb=63a8840ff755de24d7a205f7ccc07ad0c68dc844 diff --git a/net.c b/net.c index 205041fd..dfbbc1ee 100644 --- a/net.c +++ b/net.c @@ -440,32 +440,32 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai, if (ret < 0) goto get_next_dst; sockfd = ret; - /* - * Reuse the address on passive sockets to avoid failure on - * restart (protocols using listen()) and when creating - * multiple listener instances (UDP multicast). - */ - if (passive && setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, - &on, sizeof(on)) == -1) { - ret = -ERRNO_TO_PARA_ERROR(errno); - close(sockfd); - PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n", - para_strerror(-ret)); - break; - } flowopt_setopts(sockfd, fo); - - if (src) { + if (passive) { + /* + * Reuse the address on passive sockets to avoid + * failure on restart (protocols using listen()) and + * when creating multiple listener instances (UDP + * multicast). + */ + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, + sizeof(on)) == -1) { + ret = -ERRNO_TO_PARA_ERROR(errno); + close(sockfd); + PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n", + para_strerror(-ret)); + break; + } if (bind(sockfd, src->ai_addr, src->ai_addrlen) < 0) { close(sockfd); goto get_next_src; } /* bind completed successfully */ break; + } else { + if (connect(sockfd, dst->ai_addr, dst->ai_addrlen) == 0) + break; /* connection completed successfully */ } - - if (dst && connect(sockfd, dst->ai_addr, dst->ai_addrlen) == 0) - break; /* connection completed successfully */ close(sockfd); get_next_dst: if (dst && (dst = dst->ai_next))