]> git.saurik.com Git - apple/libresolv.git/commitdiff
libresolv-64.tar.gz macos-1012 macos-10121 macos-10122 macos-10123 macos-10124 macos-10125 macos-10126 os-x-1012 v64
authorApple <opensource@apple.com>
Wed, 12 Aug 2015 22:37:47 +0000 (22:37 +0000)
committerApple <opensource@apple.com>
Wed, 12 Aug 2015 22:37:47 +0000 (22:37 +0000)
res_send.c

index a28b9f476aa6d120116a967130cd74fc6c4751f9..7a0f6c45a9d73b0d5c745f68d0edc7a4f588f8e9 100644 (file)
@@ -163,11 +163,14 @@ int interrupt_pipe_enabled = 0;
 pthread_key_t interrupt_pipe_key;
 
 static int
-bind_random(int sock)
+bind_random(int sock, int family)
 {
        int i, status;
        uint16_t src_port;
-       struct sockaddr_in local;
+       struct sockaddr_storage local;
+       struct sockaddr_in *sin;
+       struct sockaddr_in6 *sin6;
+       struct sockaddr *sa;
 
        src_port = 0;
        status = -1;
@@ -176,11 +179,24 @@ bind_random(int sock)
        {               
                /* random port in the range RANDOM_BIND_FIRST to RANDOM_BIND_LAST */
                src_port = (res_randomid() % (RANDOM_BIND_LAST - RANDOM_BIND_FIRST)) + RANDOM_BIND_FIRST;
-               memset(&local, 0, sizeof(struct sockaddr_in));
-               local.sin_family = AF_INET;
-               local.sin_port = htons(src_port);
+               memset(&local, 0, sizeof(local));
+               switch (family) {
+               case AF_INET:
+                       sin = (struct sockaddr_in *)&local;
+                       sin->sin_len = sizeof(struct sockaddr_in);
+                       sin->sin_family = family;
+                       sin->sin_port = htons(src_port);
+                       break;
+               case AF_INET6:
+                       sin6 = (struct sockaddr_in6 *)&local;
+                       sin6->sin6_len = sizeof(struct sockaddr_in6);
+                       sin6->sin6_family = family;
+                       sin6->sin6_port = htons(src_port);
+                       break;
+               }
 
-               status = bind(sock, (struct sockaddr *)&local, sizeof(struct sockaddr_in));
+               sa = (struct sockaddr *)&local;
+               status = bind(sock, sa, sa->sa_len);
        }
 
        return status;
@@ -1192,7 +1208,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, int *anssiz
                        return DNS_RES_STATUS_SYSTEM_ERROR;
                }
 
-               bind_random(EXT(statp).nssocks[ns]);
+               bind_random(EXT(statp).nssocks[ns], nsap->sa_family);
 
 #ifndef CANNOT_CONNECT_DGRAM
                /*