From 82b4df67514f258976152031fce44b9dfe249435 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 15 Dec 2006 23:28:23 +0000 Subject: Make code endianess save --- trackerlogic.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'trackerlogic.c') diff --git a/trackerlogic.c b/trackerlogic.c index e9b9b2e..7b3c5db 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -18,9 +18,7 @@ // Helper functions for binary_find // int compare_hash( const void *hash1, const void *hash2 ) { return memcmp( hash1, hash2, sizeof( ot_hash )); } -int compare_ip_port( const void *peer1, const void *peer2 ) { -if( ((ot_peer*)peer1)->ip != ((ot_peer*)peer2)->ip ) return ((ot_peer*)peer1)->ip - ((ot_peer*)peer2)->ip; -return ((ot_peer*)peer1)->port_flags - ((ot_peer*)peer2)->port_flags; } +int compare_ip_port( const void *peer1, const void *peer2 ) { return memcmp( peer1, peer2, 6 ); } static void *binary_search( const void *key, const void *base, unsigned long member_count, const unsigned long member_size, @@ -82,7 +80,7 @@ static int vector_remove_peer( ot_vector *vector, ot_peer *peer ) { match = BINARY_FIND( peer, vector->data, vector->size, sizeof( ot_peer ), compare_ip_port, &exactmatch ); if( !exactmatch ) return 0; - exactmatch = match->port_flags & PEER_FLAG_SEEDING ? 2 : 1; + exactmatch = OT_FLAG( match ) & PEER_FLAG_SEEDING ? 2 : 1; MEMMOVE( match, match + 1, ((ot_peer*)vector->data) + vector->size - match - 1 ); vector->size--; return exactmatch; @@ -164,7 +162,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { if( !exactmatch ) { int i; MEMMOVE( peer_dest, peer, sizeof( ot_peer ) ); - if( peer->port_flags & PEER_FLAG_SEEDING ) + if( OT_FLAG(peer) & PEER_FLAG_SEEDING ) torrent->peer_list->seed_count[0]++; for( i=1; ipeer_list->peers[i], peer ) ) { @@ -174,12 +172,12 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { } } } else { - if( (peer_dest->port_flags & PEER_FLAG_SEEDING ) && !(peer->port_flags & PEER_FLAG_SEEDING ) ) + if( (OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && !(OT_FLAG(peer) & PEER_FLAG_SEEDING ) ) torrent->peer_list->seed_count[0]--; - if( !(peer_dest->port_flags & PEER_FLAG_SEEDING ) && (peer->port_flags & PEER_FLAG_SEEDING ) ) + if( !(OT_FLAG(peer_dest) & PEER_FLAG_SEEDING ) && (OT_FLAG(peer) & PEER_FLAG_SEEDING ) ) torrent->peer_list->seed_count[0]++; } - if( peer->port_flags & PEER_FLAG_COMPLETED ) + if( OT_FLAG(peer) & PEER_FLAG_COMPLETED ) torrent->peer_list->downloaded++; return torrent; -- cgit v1.2.3