- Timestamp:
- May 1, 2010, 3:53:16 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.9x/libtransmission/net.c
r10111 r10570 442 442 443 443 /* 444 get_source_address(), get_name_source_address(), and 445 global_unicast_address() were written by Juliusz Chroboczek, 446 and are covered under the same license as dht.c. 447 Please feel free to copy them into your software 448 if it can help unbreaking the double-stack Internet. */ 444 get_source_address() and global_unicast_address() were written by 445 Juliusz Chroboczek, and are covered under the same license as dht.c. 446 Please feel free to copy them into your software if it can help 447 unbreaking the double-stack Internet. */ 449 448 450 449 /* Get the source address used for a given destination address. Since … … 482 481 errno = save; 483 482 return -1; 484 }485 486 /* Like above, but for a given DNS name. */487 static int488 get_name_source_address(int af, const char *name,489 struct sockaddr *src, socklen_t *src_len)490 {491 struct addrinfo hints, *info, *infop;492 int rc;493 494 memset(&hints, 0, sizeof(hints));495 hints.ai_family = af;496 hints.ai_socktype = SOCK_DGRAM;497 498 rc = getaddrinfo(name, "80", &hints, &info);499 if(rc != 0) {500 errno = ENOENT;501 return -1;502 }503 504 rc = -1;505 errno = ENOENT;506 infop = info;507 while(infop) {508 if(infop->ai_addr->sa_family == af) {509 rc = get_source_address(infop->ai_addr, infop->ai_addrlen,510 src, src_len);511 if(rc >= 0)512 break;513 }514 infop = infop->ai_next;515 }516 517 freeaddrinfo(info);518 return rc;519 483 } 520 484 … … 546 510 { 547 511 struct sockaddr_storage ss; 548 socklen_t ss_len = sizeof(ss); 512 socklen_t sslen = sizeof(ss); 513 struct sockaddr_in sin; 514 struct sockaddr_in6 sin6; 515 struct sockaddr *sa; 516 socklen_t salen; 549 517 int rc; 550 518 551 /* This should be a name with both IPv4 and IPv6 addresses. */ 552 rc = get_name_source_address( af, "www.transmissionbt.com", 553 (struct sockaddr*)&ss, &ss_len ); 554 /* In case Charles removes IPv6 from his website. */ 555 if( rc < 0 ) 556 rc = get_name_source_address( af, "www.ietf.org", 557 (struct sockaddr*)&ss, &ss_len ); 519 switch(af) { 520 case AF_INET: 521 memset(&sin, 0, sizeof(sin)); 522 sin.sin_family = AF_INET; 523 inet_pton(AF_INET, "91.121.74.28", &sin.sin_addr); 524 sin.sin_port = htons(6969); 525 sa = (struct sockaddr*)&sin; 526 salen = sizeof(sin); 527 break; 528 case AF_INET6: 529 memset(&sin6, 0, sizeof(sin6)); 530 sin6.sin6_family = AF_INET6; 531 /* In order for address selection to work right, this should be 532 a native IPv6 address, not Teredo or 6to4. */ 533 inet_pton(AF_INET6, "2001:1890:1112:1::20", &sin6.sin6_addr); 534 sin6.sin6_port = htons(6969); 535 sa = (struct sockaddr*)&sin6; 536 salen = sizeof(sin6); 537 break; 538 default: 539 return -1; 540 } 541 542 rc = get_source_address( sa, salen, (struct sockaddr*)&ss, &sslen ); 558 543 559 544 if( rc < 0 )
Note: See TracChangeset
for help on using the changeset viewer.