1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

(trunk libT) add some assertions to tr_compareAddresses()

This commit is contained in:
Charles Kerr 2008-12-16 06:46:27 +00:00
parent 3739f5c72c
commit 748a9f1c92

View file

@ -127,27 +127,25 @@ tr_normalizeV4Mapped( tr_address * const addr )
* >0 if a > b
* 0 if a == b
*/
int
tr_compareAddresses( const tr_address * a, const tr_address * b)
{
int retval;
int addrlen;
int
tr_compareAddresses( const tr_address * a, const tr_address * b)
{
int addrlen;
assert( a );
assert( b );
assert( a->type == TR_AF_INET || a->type == TR_AF_INET6 );
assert( b->type == TR_AF_INET || b->type == TR_AF_INET6 );
/* IPv6 addresses are always "greater than" IPv4 */
if( a->type == TR_AF_INET && b->type == TR_AF_INET6 )
return 1;
if( a->type == TR_AF_INET6 && b->type == TR_AF_INET )
return -1;
if( a->type != b->type )
return a->type == TR_AF_INET ? 1 : -1;
if( a->type == TR_AF_INET )
addrlen = sizeof( struct in_addr );
else
addrlen = sizeof( struct in6_addr );
retval = memcmp( &a->addr, &b->addr, addrlen );
if( retval == 0 )
return 0;
return retval;
return memcmp( &a->addr, &b->addr, addrlen );
}
/***********************************************************************