Ignore:
Timestamp:
Apr 15, 2009, 9:05:58 PM (13 years ago)
Author:
jhujhiti
Message:

(trunk) #1497 Options to listen on specific network sockets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r8217 r8242  
    155155{
    156156    int retval = inet_pton( AF_INET, src, &dst->addr );
     157    assert( dst );
    157158    if( retval < 0 )
    158159        return NULL;
     
    317318}
    318319
     320const tr_address *
     321tr_socketListGetType( const tr_socketList * const el, tr_address_type type )
     322{
     323    const tr_socketList * tmp = el;
     324    while( tmp )
     325    {
     326        if( tmp->addr.type == type )
     327            return &tmp->addr;
     328        tmp = tmp->next;
     329    }
     330    return NULL;
     331}
     332
    319333/***********************************************************************
    320334 * TCP sockets
     
    447461}
    448462
     463const tr_socketList * tr_getSessionBindSockets( const tr_session * session );
     464
    449465int
    450466tr_netOpenTCP( tr_session        * session,
     
    456472    const int               type = SOCK_STREAM;
    457473    socklen_t               addrlen;
     474    const tr_address      * source_addr;
     475    socklen_t               sourcelen;
     476    struct sockaddr_storage source_sock;
    458477
    459478    assert( tr_isAddress( addr ) );
     
    468487
    469488    addrlen = setup_sockaddr( addr, port, &sock );
     489   
     490    /* set source address */
     491    source_addr = tr_socketListGetType( tr_getSessionBindSockets( session ),
     492                                        addr->type );
     493    assert( source_addr );
     494    sourcelen = setup_sockaddr( source_addr, 0, &source_sock );
     495    if( bind( s, ( struct sockaddr * ) &source_sock, sourcelen ) )
     496    {
     497        tr_err( _( "Couldn't set source address %s on %d: %s" ),
     498                tr_ntop_non_ts( source_addr ), s, tr_strerror( errno ) );
     499        return -errno;
     500    }
    470501
    471502    if( ( connect( s, (struct sockaddr *) &sock,
Note: See TracChangeset for help on using the changeset viewer.