]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3906 "DHT ignores bind-address-ipv6" -- test fix.
authorJordan Lee <jordan@transmissionbt.com>
Sat, 22 Jan 2011 13:49:15 +0000 (13:49 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 22 Jan 2011 13:49:15 +0000 (13:49 +0000)
Add code to honor the ipv6 bind address. Thanks to jch for saving me a little work by confirming the bug and pointing out where in the code the change needed to be made.

libtransmission/tr-udp.c

index ab56b81c46675d5afd54e04febe0780cc15f2e49..5cfdb82171cd1cc9919515899275839c7f4702c9 100644 (file)
@@ -38,6 +38,8 @@ THE SOFTWARE.
 static void
 rebind_ipv6(tr_session *ss, tr_bool force)
 {
+    tr_bool is_default;
+    const struct tr_address * public_addr;
     struct sockaddr_in6 sin6;
     const unsigned char *ipv6 = tr_globalIPv6();
     int s = -1, rc;
@@ -71,6 +73,10 @@ rebind_ipv6(tr_session *ss, tr_bool force)
     if(ipv6)
         memcpy(&sin6.sin6_addr, ipv6, 16);
     sin6.sin6_port = htons(ss->udp_port);
+    public_addr = tr_sessionGetPublicAddress(ss, TR_AF_INET6, &is_default);
+    if(public_addr && !is_default)
+        sin6.sin6_addr = public_addr->addr.addr6;
+
     rc = bind(s, (struct sockaddr*)&sin6, sizeof(sin6));
     if(rc < 0)
         goto fail;