Changeset 7847
- Timestamp:
- Feb 8, 2009, 12:29:20 AM (12 years ago)
- Location:
- branches/1.5x/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5x/libtransmission/net.c
r7741 r7847 243 243 } 244 244 245 tr_net_af_support 246 tr_net_getAFSupport( tr_port port ) 247 { 248 /* Do we care if an address is in use? Probably not, since it will be 249 * caught later. This will only set up the list of sockets to bind. */ 250 static tr_bool alreadyDone = FALSE; 251 static tr_net_af_support support = { FALSE, FALSE }; 252 int s4, s6; 245 tr_bool 246 tr_net_hasIPv6( tr_port port ) 247 { 248 static tr_bool alreadyDone = FALSE; 249 static tr_bool result = FALSE; 250 int s; 253 251 if( alreadyDone ) 254 return support; 255 s6 = tr_netBindTCP( &tr_in6addr_any, port, TRUE ); 256 if( s6 >= 0 || -s6 != EAFNOSUPPORT ) /* we support ipv6 */ 257 { 258 listen( s6, 1 ); 259 support.has_inet6 = TRUE; 260 } 261 s4 = tr_netBindTCP( &tr_inaddr_any, port, TRUE ); 262 if( s4 >= 0 ) /* we bound *with* the ipv6 socket bound (need both) 263 * or only have ipv4 */ 264 { 265 tr_netClose( s4 ); 266 support.needs_inet4 = TRUE; 267 } 268 if( s6 >= 0 ) 269 tr_netClose( s6 ); 252 return result; 253 s = tr_netBindTCP( &tr_in6addr_any, port, TRUE ); 254 if( s >= 0 || -s != EAFNOSUPPORT ) /* we support ipv6 */ 255 { 256 result = TRUE; 257 tr_netClose( s ); 258 } 270 259 alreadyDone = TRUE; 271 return support;260 return result; 272 261 } 273 262 … … 538 527 const int type = SOCK_STREAM; 539 528 int addrlen; 540 541 #if defined( SO_REUSEADDR ) || defined( SO_REUSEPORT ) 542 int optval; 529 int retval; 530 531 #if defined( SO_REUSEADDR ) || defined( SO_REUSEPORT ) || defined( IPV6_V6ONLY ) 532 int optval = 1; 543 533 #endif 544 534 … … 550 540 551 541 #ifdef SO_REUSEADDR 552 optval = 1;553 542 setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof( optval ) ); 543 #endif 544 545 #ifdef IPV6_V6ONLY 546 if( retval = setsockopt( s, IPPROTO_IPV6, IPV6_V6ONLY, &optval, 547 sizeof( optval ) ) == -1 ) { 548 /* the kernel may not support this. if not, ignore it */ 549 if( errno != ENOPROTOOPT ) 550 return -errno; 551 } 554 552 #endif 555 553 -
branches/1.5x/libtransmission/net.h
r7741 r7847 95 95 static TR_INLINE tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); } 96 96 97 typedef struct tr_net_af_support 98 { 99 tr_bool has_inet6; 100 tr_bool needs_inet4; 101 } tr_net_af_support; 102 103 tr_net_af_support tr_net_getAFSupport( tr_port ); 97 tr_bool tr_net_hasIPv6( tr_port ); 104 98 105 99 /*********************************************************************** -
branches/1.5x/libtransmission/port-forwarding.c
r7722 r7847 225 225 setupBindSockets( tr_port port ) 226 226 { 227 tr_ net_af_support support = tr_net_getAFSupport( port );227 tr_bool hasIPv6 = tr_net_hasIPv6( port ); 228 228 tr_socketList * socks = NULL; 229 if( support.has_inet6 )229 if( hasIPv6 ) 230 230 socks = tr_socketListNew( &tr_in6addr_any ); 231 if( support.needs_inet4 ) 232 { 233 if( socks ) 234 tr_socketListAppend( socks, &tr_inaddr_any ); 235 else 236 socks = tr_socketListNew( &tr_inaddr_any ); 237 } 231 232 if( socks ) 233 tr_socketListAppend( socks, &tr_inaddr_any ); 234 else 235 socks = tr_socketListNew( &tr_inaddr_any ); 238 236 return socks; /* Because the dryer gremlins won't */ 239 237 }
Note: See TracChangeset
for help on using the changeset viewer.