Changeset 7436


Ignore:
Timestamp:
Dec 18, 2008, 5:55:22 AM (12 years ago)
Author:
jhujhiti
Message:

(trunk libT) Refactor ipv6 bind socket check

This will let the RPC server use the same test mechanism eventually. Networking code belongs in net.c anyway.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r7417 r7436  
    156156}
    157157
     158tr_net_af_support
     159tr_net_getAFSupport( tr_port port )
     160{
     161    /* Do we care if an address is in use? Probably not, since it will be
     162     * caught later. This will only set up the list of sockets to bind. */
     163    static tr_bool alreadyDone       = FALSE;
     164    static tr_net_af_support support = { FALSE, FALSE };
     165    int s4, s6;
     166    if( alreadyDone )
     167        return support;
     168    s6 = tr_netBindTCP( &tr_in6addr_any, port, TRUE );
     169    if( s6 >= 0 || -s6 != EAFNOSUPPORT ) /* we support ipv6 */
     170    {
     171        listen( s6, 1 );
     172        support.has_inet6 = TRUE;
     173    }
     174    s4 = tr_netBindTCP( &tr_inaddr_any, port, TRUE );
     175    if( s4 >= 0 ) /* we bound *with* the ipv6 socket bound (need both)
     176                   * or only have ipv4 */
     177    {
     178        tr_netClose( s4 );
     179        support.needs_inet4 = TRUE;
     180    }
     181    if( s6 >= 0 )
     182        tr_netClose( s6 );
     183    alreadyDone = TRUE;
     184    return support;
     185}
     186
    158187/***********************************************************************
    159188 * Socket list housekeeping
  • trunk/libtransmission/net.h

    r7425 r7436  
    8888tr_bool tr_isAddress( const tr_address * a );
    8989
     90typedef struct tr_net_af_support
     91{
     92    tr_bool has_inet6;
     93    tr_bool needs_inet4;
     94} tr_net_af_support;
     95
     96tr_net_af_support tr_net_getAFSupport( tr_port );
     97
    9098/***********************************************************************
    9199 * Socket list housekeeping
  • trunk/libtransmission/port-forwarding.c

    r7404 r7436  
    235235setupBindSockets( tr_port port )
    236236{
    237     /* Do we care if an address is in use? Probably not, since it will be
    238      * caught later. This will only set up the list of sockets to bind. */
    239     int s4, s6;
     237    tr_net_af_support support = tr_net_getAFSupport( port );
    240238    tr_socketList * socks = NULL;
    241     s6 = tr_netBindTCP( &tr_in6addr_any, port, TRUE );
    242     if( s6 >= 0 || -s6 != EAFNOSUPPORT ) /* we support ipv6 */
    243     {
     239    if( support.has_inet6 )
    244240        socks = tr_socketListNew( &tr_in6addr_any );
    245         listen( s6, 1 );
    246     }
    247     s4 = tr_netBindTCP( &tr_inaddr_any, port, TRUE );
    248     if( s4 >= 0 ) /* we bound *with* the ipv6 socket bound (need both)
    249                    * or only have ipv4 */
     241    if( support.needs_inet4 )
    250242    {
    251243        if( socks )
     
    253245        else
    254246            socks = tr_socketListNew( &tr_inaddr_any );
    255         tr_netClose( s4 );
    256     }
    257     if( s6 >= 0 )
    258         tr_netClose( s6 );
    259     return socks;
     247    }
     248    return socks; /* Because the dryer gremlins won't */
    260249}
    261250
Note: See TracChangeset for help on using the changeset viewer.