Changeset 7740


Ignore:
Timestamp:
Jan 17, 2009, 11:14:35 PM (12 years ago)
Author:
charles
Message:

(trunk libT) discard peers from the tracker or pex that have a port of 0 or a multicast address.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r7730 r7740  
    5858    { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };
    5959
    60 
    6160#ifdef WIN32
    6261static const char *
     
    463462}
    464463
     464static tr_bool
     465isMulticastAddress( const tr_address * addr )
     466{
     467    if( addr->type == TR_AF_INET && IN_MULTICAST( htonl( addr->addr.addr4.s_addr ) ) )
     468        return TRUE;
     469
     470    if( addr->type == TR_AF_INET6 && ( addr->addr.addr6.s6_addr[0] == 0xff ) )
     471        return TRUE;
     472
     473    return FALSE;
     474}
     475
     476tr_bool
     477tr_isValidPeerAddress( const tr_address * addr, tr_port port )
     478{
     479    if( isMulticastAddress( addr ) )
     480        return FALSE;
     481
     482    if( port == 0 )
     483        return FALSE;
     484
     485    return TRUE;
     486}
     487
    465488int
    466489tr_netOpenTCP( tr_session        * session,
     
    475498    assert( tr_isAddress( addr ) );
    476499
    477     /* don't try to connect to multicast addresses */
    478     if( addr->type == TR_AF_INET && IN_MULTICAST( htonl( addr->addr.addr4.s_addr ) ) )
    479         return -EINVAL;
    480     if( addr->type == TR_AF_INET6 && ( addr->addr.addr6.s6_addr[0] == 0xff ) )
     500    if( isMulticastAddress( addr ) )
    481501        return -EINVAL;
    482502
  • trunk/libtransmission/net.h

    r7663 r7740  
    8989void tr_normalizeV4Mapped( tr_address * const addr );
    9090
     91tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
     92
    9193void tr_suspectAddress( const tr_address * a, const char * source );
    9294
  • trunk/libtransmission/peer-mgr.c

    r7712 r7740  
    13161316
    13171317        if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
    1318             ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
     1318            if( tr_isValidPeerAddress( &pex->addr, pex->port ) )
     1319                ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
    13191320
    13201321        managerUnlock( t->manager );
Note: See TracChangeset for help on using the changeset viewer.