Ticket #3528: interface.diff

File interface.diff, 3.8 KB (added by charles, 10 years ago)

possible implementation of Harry's second suggestion

  • libtransmission/web.c

     
    143143createEasy( tr_session * s, struct tr_web_task * task )
    144144{
    145145    const tr_address * addr;
     146    tr_bool is_default_value;
    146147    CURL * e = curl_easy_init( );
    147148    const long verbose = getenv( "TR_CURL_VERBOSE" ) != NULL;
    148149    char * cookie_filename = tr_buildPath( s->configDir, "cookies.txt", NULL );
     
    167168    curl_easy_setopt( e, CURLOPT_WRITEDATA, task );
    168169    curl_easy_setopt( e, CURLOPT_WRITEFUNCTION, writeFunc );
    169170
    170     if(( addr = tr_sessionGetPublicAddress( s, TR_AF_INET )))
     171    if((( addr = tr_sessionGetPublicAddress( s, TR_AF_INET, &is_default_value ))) && !is_default_value )
    171172        curl_easy_setopt( e, CURLOPT_INTERFACE, tr_ntop_non_ts( addr ) );
     173    else if ((( addr = tr_sessionGetPublicAddress( s, TR_AF_INET6, &is_default_value ))) && !is_default_value )
     174        curl_easy_setopt( e, CURLOPT_INTERFACE, tr_ntop_non_ts( addr ) );
    172175
    173176    if( task->range )
    174177        curl_easy_setopt( e, CURLOPT_RANGE, task->range );
  • libtransmission/session.c

     
    218218}
    219219
    220220const tr_address*
    221 tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type )
     221tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type, tr_bool * is_default_value )
    222222{
     223    const char * default_value;
    223224    const struct tr_bindinfo * bindinfo;
    224225
    225226    switch( tr_af_type )
    226227    {
    227         case TR_AF_INET:  bindinfo = session->public_ipv4; break;
    228         case TR_AF_INET6: bindinfo = session->public_ipv6; break;
    229         default:          bindinfo = NULL;                 break;
     228        case TR_AF_INET:
     229            bindinfo = session->public_ipv4;
     230            default_value = TR_DEFAULT_BIND_ADDRESS_IPV4;
     231            break;
     232
     233        case TR_AF_INET6:
     234            bindinfo = session->public_ipv6;
     235            default_value = TR_DEFAULT_BIND_ADDRESS_IPV6;
     236            break;
     237
     238        default:
     239            bindinfo = NULL;
     240            default_value = "";
     241            break;
    230242    }
    231243
     244    if( is_default_value != NULL )
     245        *is_default_value = !strcmp( default_value, tr_ntop_non_ts( &bindinfo->addr ) );
     246
    232247    return bindinfo ? &bindinfo->addr : NULL;
    233248}
    234249
  • libtransmission/net.c

     
    315315    addrlen = setup_sockaddr( addr, port, &sock );
    316316
    317317    /* set source address */
    318     source_addr = tr_sessionGetPublicAddress( session, addr->type );
     318    source_addr = tr_sessionGetPublicAddress( session, addr->type, NULL );
    319319    assert( source_addr );
    320320    sourcelen = setup_sockaddr( source_addr, 0, &source_sock );
    321321    if( bind( s, ( struct sockaddr * ) &source_sock, sourcelen ) )
  • libtransmission/session.h

     
    224224
    225225tr_bool      tr_sessionIsLocked( const tr_session * );
    226226
    227 const struct tr_address*  tr_sessionGetPublicAddress( const tr_session *, int tr_af_type );
     227const struct tr_address*  tr_sessionGetPublicAddress( const tr_session  * session,
     228                                                      int                 tr_af_type,
     229                                                      tr_bool           * is_default_value );
    228230
     231
    229232struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
    230233
    231234int tr_sessionCountTorrents( const tr_session * session );