From 1ecbe8da6519c53cecd006a6ea552b84c1c203d3 Mon Sep 17 00:00:00 2001 From: Josh Elsasser Date: Sat, 14 Jul 2007 16:29:21 +0000 Subject: [PATCH] Change a couple functions to take an in_addr pointer instead of an in_addr. Forward declare struct in_addr and include the relevant headers in the .c files where it's used. --- libtransmission/fdlimit.c | 6 +++++- libtransmission/http.c | 9 +++++++-- libtransmission/internal.h | 3 --- libtransmission/natpmp.c | 9 +++++++-- libtransmission/net.c | 16 ++++++++++------ libtransmission/net.h | 7 +++++-- libtransmission/peer.c | 12 +++++++++--- libtransmission/peer.h | 3 ++- libtransmission/platform.c | 4 ++++ libtransmission/shared.c | 7 ++++++- libtransmission/torrent.c | 7 ++++++- libtransmission/tracker.c | 5 +++++ libtransmission/upnp.c | 7 ++++++- 13 files changed, 72 insertions(+), 23 deletions(-) diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index dbcb89f24..18172dccd 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -22,10 +22,14 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#include #include #include +#include +#include +#include #include +#include + #include "transmission.h" #define TR_MAX_OPEN_FILES 16 /* That is, real files, not sockets */ diff --git a/libtransmission/http.c b/libtransmission/http.c index 153655f1e..e22f97c5f 100644 --- a/libtransmission/http.c +++ b/libtransmission/http.c @@ -22,7 +22,12 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include #include + #include "transmission.h" #include "http.h" #include "net.h" @@ -562,7 +567,7 @@ tr_httpPulse( tr_http_t * http, const char ** data, int * len ) } if( !tr_netResolve( http->host, &addr ) ) { - http->sock = tr_netOpenTCP( addr, htons( http->port ), 1 ); + http->sock = tr_netOpenTCP( &addr, htons( http->port ), 1 ); http->state = HTTP_STATE_CONNECT; break; } @@ -584,7 +589,7 @@ tr_httpPulse( tr_http_t * http, const char ** data, int * len ) case TR_NET_OK: tr_netResolveClose( http->resolve ); http->resolve = NULL; - http->sock = tr_netOpenTCP( addr, htons( http->port ), 1 ); + http->sock = tr_netOpenTCP( &addr, htons( http->port ), 1 ); http->state = HTTP_STATE_CONNECT; } /* fallthrough */ diff --git a/libtransmission/internal.h b/libtransmission/internal.h index 8c0a16f9d..bf601b575 100644 --- a/libtransmission/internal.h +++ b/libtransmission/internal.h @@ -44,9 +44,6 @@ int vasprintf( char **, const char *, va_list ); #ifndef __AMIGAOS4__ #include #endif -#include -#include -#include #include #ifdef SYS_BEOS # define socklen_t uint32_t diff --git a/libtransmission/natpmp.c b/libtransmission/natpmp.c index fe998ad27..a1d211c16 100644 --- a/libtransmission/natpmp.c +++ b/libtransmission/natpmp.c @@ -22,6 +22,11 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include + #include "transmission.h" #include "natpmp.h" #include "net.h" @@ -510,7 +515,7 @@ newreq( int adding, struct in_addr addr, int port ) return NULL; } - ret->fd = tr_netOpenUDP( addr, htons( PMP_PORT ), 1 ); + ret->fd = tr_netOpenUDP( &addr, htons( PMP_PORT ), 1 ); if( 0 > ret->fd ) { free( ret ); @@ -666,7 +671,7 @@ mcastsetup() struct in_addr addr; addr.s_addr = inet_addr( PMP_MCAST_ADDR ); - fd = tr_netMcastOpen( PMP_PORT, addr ); + fd = tr_netMcastOpen( PMP_PORT, &addr ); if( 0 > fd ) { return -1; diff --git a/libtransmission/net.c b/libtransmission/net.c index 274df69ff..91a95be0a 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -22,10 +22,13 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#include +#include #include #include +#include +#include #include + #include "transmission.h" #include "fdlimit.h" #include "net.h" @@ -264,7 +267,8 @@ static int createSocket( int type, int priority ) return makeSocketNonBlocking( s ); } -int tr_netOpen( struct in_addr addr, in_port_t port, int type, int priority ) +int tr_netOpen( const struct in_addr * addr, in_port_t port, + int type, int priority ) { int s; struct sockaddr_in sock; @@ -276,7 +280,7 @@ int tr_netOpen( struct in_addr addr, in_port_t port, int type, int priority ) memset( &sock, 0, sizeof( sock ) ); sock.sin_family = AF_INET; - sock.sin_addr.s_addr = addr.s_addr; + sock.sin_addr.s_addr = addr->s_addr; sock.sin_port = port; if( connect( s, (struct sockaddr *) &sock, @@ -292,7 +296,7 @@ int tr_netOpen( struct in_addr addr, in_port_t port, int type, int priority ) } #ifdef IP_ADD_MEMBERSHIP -int tr_netMcastOpen( int port, struct in_addr addr ) +int tr_netMcastOpen( int port, const struct in_addr * addr ) { int fd; struct ip_mreq req; @@ -304,7 +308,7 @@ int tr_netMcastOpen( int port, struct in_addr addr ) } memset( &req, 0, sizeof( req ) ); - req.imr_multiaddr.s_addr = addr.s_addr; + req.imr_multiaddr.s_addr = addr->s_addr; req.imr_interface.s_addr = htonl( INADDR_ANY ); if( setsockopt( fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &req, sizeof ( req ) ) ) { @@ -316,7 +320,7 @@ int tr_netMcastOpen( int port, struct in_addr addr ) return fd; } #else /* IP_ADD_MEMBERSHIP */ -int tr_netMcastOpen( int port UNUSED, struct in_addr addr UNUSED ) +int tr_netMcastOpen( int port UNUSED, const struct in_addr * addr UNUSED ) { return -1; } diff --git a/libtransmission/net.h b/libtransmission/net.h index e3b189768..d2ec110ae 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -23,6 +23,9 @@ *****************************************************************************/ +struct in_addr; +struct sockaddr_in; + /*********************************************************************** * DNS resolution **********************************************************************/ @@ -43,9 +46,9 @@ void tr_netResolveClose( tr_resolve_t * ); tr_netOpen( (addr), (port), SOCK_STREAM, (priority) ) #define tr_netOpenUDP( addr, port, priority ) \ tr_netOpen( (addr), (port), SOCK_DGRAM, (priority) ) -int tr_netOpen ( struct in_addr addr, in_port_t port, int type, +int tr_netOpen ( const struct in_addr * addr, in_port_t port, int type, int priority ); -int tr_netMcastOpen( int port, struct in_addr addr ); +int tr_netMcastOpen( int port, const struct in_addr * addr ); #define tr_netBindTCP( port ) tr_netBind( (port), SOCK_STREAM ) #define tr_netBindUDP( port ) tr_netBind( (port), SOCK_DGRAM ) int tr_netBind ( int port, int type ); diff --git a/libtransmission/peer.c b/libtransmission/peer.c index eeb6195cc..799b97ccd 100644 --- a/libtransmission/peer.c +++ b/libtransmission/peer.c @@ -22,7 +22,12 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include #include + #include "transmission.h" #include "bencode.h" #include "clients.h" /* for tr_clientForId() */ @@ -232,7 +237,8 @@ static void __peer_dbg( tr_peer_t * peer, char * msg, ... ) *********************************************************************** * Initializes a new peer. **********************************************************************/ -tr_peer_t * tr_peerInit( struct in_addr addr, in_port_t port, int s, int from ) +tr_peer_t * tr_peerInit( const struct in_addr * addr, in_port_t port, + int s, int from ) { tr_peer_t * peer; @@ -251,7 +257,7 @@ tr_peer_t * tr_peerInit( struct in_addr addr, in_port_t port, int s, int from ) peer->inRequests = tr_new0( tr_request_t, peer->inRequestAlloc ); peer->socket = s; - peer->addr = addr; + peer->addr = *addr; peer->port = port; peer->from = from; peer->credit = SWIFT_INITIAL_CREDIT; @@ -463,7 +469,7 @@ int tr_peerPulse( tr_peer_t * peer ) /* Connect */ if( PEER_STATUS_IDLE == peer->status ) { - peer->socket = tr_netOpenTCP( peer->addr, peer->port, 0 ); + peer->socket = tr_netOpenTCP( &peer->addr, peer->port, 0 ); if( peer->socket < 0 ) { return TR_ERROR; diff --git a/libtransmission/peer.h b/libtransmission/peer.h index 5f471c5b8..468077a6f 100644 --- a/libtransmission/peer.h +++ b/libtransmission/peer.h @@ -27,9 +27,10 @@ #include "transmission.h" +struct in_addr; typedef struct tr_peer_s tr_peer_t; -tr_peer_t * tr_peerInit ( struct in_addr, in_port_t, int sock, int ); +tr_peer_t * tr_peerInit ( const struct in_addr *, in_port_t, int sock, int ); void tr_peerDestroy ( tr_peer_t * ); const char *tr_peerClient ( tr_peer_t * ); void tr_peerSetPrivate ( tr_peer_t *, int ); diff --git a/libtransmission/platform.c b/libtransmission/platform.c index 7174c57f4..4196b41a2 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -383,6 +383,10 @@ void tr_condClose( tr_cond_t * c ) #if defined( BSD ) +#include +#include +#include +#include #include #include diff --git a/libtransmission/shared.c b/libtransmission/shared.c index b38639f9f..019aa77f0 100644 --- a/libtransmission/shared.c +++ b/libtransmission/shared.c @@ -22,6 +22,11 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include + #include "transmission.h" #include "choking.h" #include "natpmp.h" @@ -354,7 +359,7 @@ static void AcceptPeers( tr_shared_t * s ) { break; } - s->peers[s->peerCount++] = tr_peerInit( addr, 0, socket, + s->peers[s->peerCount++] = tr_peerInit( &addr, 0, socket, TR_PEER_FROM_INCOMING ); } } diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 42aea9315..241b6c9b5 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -22,6 +22,11 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include + #include "transmission.h" #include "fastresume.h" #include "trcompat.h" /* for strlcpy */ @@ -864,7 +869,7 @@ int tr_torrentAddCompact( tr_torrent_t * tor, int from, memcpy( &addr, buf, 4 ); buf += 4; memcpy( &port, buf, 2 ); buf += 2; - peer = tr_peerInit( addr, port, -1, from ); + peer = tr_peerInit( &addr, port, -1, from ); added += tr_torrentAttachPeer( tor, peer ); } diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 31df28b73..0d7756705 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -22,6 +22,11 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include + #include "transmission.h" #include "bencode.h" #include "bsdqueue.h" diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index 735f5e499..c6e90378d 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -22,7 +22,12 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include +#include +#include +#include #include + #include "transmission.h" #include "http.h" #include "net.h" @@ -407,7 +412,7 @@ mcastStart() struct in_addr addr; addr.s_addr = inet_addr( SSDP_ADDR ); - fd = tr_netMcastOpen( SSDP_PORT, addr ); + fd = tr_netMcastOpen( SSDP_PORT, &addr ); if( 0 > fd ) { return -1;