From d07b688c867e73465b0147651efc02b1f65e0db5 Mon Sep 17 00:00:00 2001 From: Josh Elsasser Date: Fri, 18 Aug 2006 08:46:19 +0000 Subject: [PATCH] Unbreak BeOS build. --- libtransmission/net.c | 9 +++++++++ libtransmission/net.h | 1 + libtransmission/transmission.c | 11 +++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libtransmission/net.c b/libtransmission/net.c index 34eac3ffc..64df37806 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -403,3 +403,12 @@ void tr_netClose( int s ) close( s ); #endif } + +void tr_netNtop( const struct in_addr * addr, char * buf, int len ) +{ + const uint8_t * cast; + + cast = (const uint8_t *)addr; + snprintf( buf, len, "%hhu.%hhu.%hhu.%hhu", + cast[0], cast[1], cast[2], cast[3] ); +} diff --git a/libtransmission/net.h b/libtransmission/net.h index 7d9e0275f..6ac74ce65 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -52,3 +52,4 @@ void tr_netClose ( int s ); int tr_netSend ( int s, uint8_t * buf, int size ); int tr_netRecv ( int s, uint8_t * buf, int size ); +void tr_netNtop( const struct in_addr * addr, char * buf, int len ); diff --git a/libtransmission/transmission.c b/libtransmission/transmission.c index 5c5cef5f8..4b096a59f 100644 --- a/libtransmission/transmission.c +++ b/libtransmission/transmission.c @@ -410,6 +410,7 @@ int tr_getFinished( tr_torrent_t * tor ) tr_stat_t * tr_torrentStat( tr_torrent_t * tor ) { tr_stat_t * s; + tr_peer_t * peer; tr_info_t * inf = &tor->info; int i; @@ -435,7 +436,6 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor ) s->peersUploading = 0; s->peersDownloading = 0; - tr_peer_t * peer; for( i = 0; i < tor->peerCount; i++ ) { peer = tor->peers[i]; @@ -494,11 +494,13 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor ) tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount ) { + tr_peer_stat_t * peers; + tr_lockLock( &tor->lock ); *peerCount = tor->peerCount; - tr_peer_stat_t * peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) ); + peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) ); if (peers != NULL) { tr_peer_t * peer; @@ -511,7 +513,7 @@ tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount ) addr = tr_peerAddress( peer ); if( NULL != addr ) { - inet_ntop( AF_INET, addr, peers[i].addr, + tr_netNtop( addr, peers[i].addr, sizeof( peers[i].addr ) ); } @@ -530,10 +532,11 @@ tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount ) void tr_torrentPeersFree( tr_peer_stat_t * peers, int peerCount ) { + int i; + if (peers == NULL) return; - int i; for (i = 0; i < peerCount; i++) free( peers[i].client );