net: Kill dead code in makesock_addrinfo().
[paraslash.git] / net.c
diff --git a/net.c b/net.c
index 2d0c9e22e1a69adeae2759209bbf56f77128b1b7..d1c6eb510f5b971389968849b713f46995932ab6 100644 (file)
--- a/net.c
+++ b/net.c
  */
 #define _GNU_SOURCE
 
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 #include <netdb.h>
 
 /* At least NetBSD needs these. */
@@ -418,7 +423,7 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                struct flowopts *fo)
 {
        struct addrinfo *local, *remote, *src = NULL, *dst = NULL;
-       int rc = -E_MAKESOCK, on = 1, sockfd = -1;
+       int ret = -E_MAKESOCK, on = 1, sockfd = -1;
 
        if (passive) {
                local = ai;
@@ -430,15 +435,11 @@ 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 */
-
-               sockfd = socket(src ? src->ai_family : dst->ai_family,
+               ret = socket(src ? src->ai_family : dst->ai_family,
                        sock_type(l4type), l4type);
-               if (sockfd < 0)
+               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
@@ -446,11 +447,10 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                 */
                if (passive && setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
                                                  &on, sizeof(on)) == -1) {
-                       rc = errno;
+                       ret = -ERRNO_TO_PARA_ERROR(errno);
                        close(sockfd);
                        PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n",
-                                      strerror(rc));
-                       rc = -ERRNO_TO_PARA_ERROR(rc);
+                               para_strerror(-ret));
                        break;
                }
                flowopt_setopts(sockfd, fo);
@@ -474,11 +474,8 @@ get_next_src:
                if (src && (src = src->ai_next)) /* restart inner loop */
                        dst = remote;
        }
-       if (src == NULL && dst == NULL) {
-               if (rc >= 0)
-                       rc = -E_MAKESOCK;
-               return rc;
-       }
+       if (src == NULL && dst == NULL)
+               return ret < 0? ret : -E_MAKESOCK;
        return sockfd;
 }