Changeset 7410


Ignore:
Timestamp:
Dec 16, 2008, 6:46:27 AM (12 years ago)
Author:
charles
Message:

(trunk libT) add some assertions to tr_compareAddresses()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r7397 r7410  
    128128 * 0  if a == b
    129129 */
    130 int
    131 tr_compareAddresses( const tr_address * a, const tr_address * b)
    132 {
    133     int retval;
    134     int addrlen;
     130int
     131tr_compareAddresses( const tr_address * a, const tr_address * b)
     132{
     133    int addrlen;
     134
     135    assert( a );
     136    assert( b );
     137    assert( a->type == TR_AF_INET || a->type == TR_AF_INET6 );
     138    assert( b->type == TR_AF_INET || b->type == TR_AF_INET6 );
    135139
    136140    /* IPv6 addresses are always "greater than" IPv4 */
    137     if( a->type == TR_AF_INET && b->type == TR_AF_INET6 )
    138         return 1;
    139     if( a->type == TR_AF_INET6 && b->type == TR_AF_INET )
    140         return -1;
     141    if( a->type != b->type )
     142        return a->type == TR_AF_INET ? 1 : -1;
    141143
    142144    if( a->type == TR_AF_INET )
     
    144146    else
    145147        addrlen = sizeof( struct in6_addr );
    146     retval = memcmp( &a->addr, &b->addr, addrlen );
    147     if( retval == 0 )
    148         return 0;
    149      
    150     return retval;
     148    return memcmp( &a->addr, &b->addr, addrlen );
    151149}
    152150
Note: See TracChangeset for help on using the changeset viewer.