Ignore:
Timestamp:
Feb 8, 2009, 12:29:20 AM (12 years ago)
Author:
jhujhiti
Message:

(1.5x libT) backport r7839 (stop using ipv4-mapped listeners)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/net.c

    r7741 r7847  
    243243}
    244244
    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;
     245tr_bool
     246tr_net_hasIPv6( tr_port port )
     247{
     248    static tr_bool alreadyDone = FALSE;
     249    static tr_bool result      = FALSE;
     250    int s;
    253251    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    }
    270259    alreadyDone = TRUE;
    271     return support;
     260    return result;
    272261}
    273262
     
    538527    const int               type = SOCK_STREAM;
    539528    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;
    543533#endif
    544534
     
    550540
    551541#ifdef SO_REUSEADDR
    552     optval = 1;
    553542    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    }
    554552#endif
    555553
Note: See TracChangeset for help on using the changeset viewer.