X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=a95f145a78ac111416201aebe4b1f628e2a73544;hp=740dfa182d4a162f2b493ac77ecebc8140c6f0ae;hb=39e1307682cb23c0007280a8a823d3017808f207;hpb=2f641bd1f56eaad88f7a63715320a3540effd902 diff --git a/net.c b/net.c index 740dfa18..a95f145a 100644 --- a/net.c +++ b/net.c @@ -12,6 +12,11 @@ */ #define _GNU_SOURCE +#include +#include +#include +#include +#include #include /* At least NetBSD needs these. */ @@ -417,7 +422,7 @@ 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) { - struct addrinfo *local, *remote, *src = NULL, *dst = NULL; + struct addrinfo *local, *remote, *src, *dst; int ret = -E_MAKESOCK, on = 1, sockfd = -1; if (passive) { @@ -430,15 +435,12 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai, /* Iterate over all src/dst combination, exhausting dst first */ for (src = local, dst = remote; src != NULL || dst != NULL; /* no op */ ) { - if (src && dst && src->ai_family == AF_INET - && dst->ai_family == AF_INET6) - goto get_next_dst; /* v4 -> v6 is not possible */ - ret = socket(src ? src->ai_family : dst->ai_family, sock_type(l4type), l4type); if (ret < 0) goto get_next_dst; sockfd = ret; + flowopt_setopts(sockfd, fo); /* * Reuse the address on passive sockets to avoid failure on * restart (protocols using listen()) and when creating @@ -452,19 +454,18 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai, para_strerror(-ret)); break; } - flowopt_setopts(sockfd, fo); - if (src) { + if (passive) { if (bind(sockfd, src->ai_addr, src->ai_addrlen) < 0) { close(sockfd); goto get_next_src; } - if (!dst) /* bind-only completed successfully */ - break; + /* 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))