(trunk libT) #3906 "DHT ignores bind-address-ipv6" -- test fix.

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.
This commit is contained in:
Jordan Lee 2011-01-22 13:49:15 +00:00
parent 53f7fbb039
commit 68130d9c4e
1 changed files with 6 additions and 0 deletions

View 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;