net: Clarify code flow of makesock_addrinfo().
[paraslash.git] / net.c
diff --git a/net.c b/net.c
index 205041f..5e4f131 100644 (file)
--- a/net.c
+++ b/net.c
@@ -455,17 +455,17 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                }
                flowopt_setopts(sockfd, fo);
 
-               if (src) {
+               if (passive) {
                        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))