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.
This commit is contained in:
Josh Elsasser
2007-07-14 16:29:21 +00:00
parent 1b5cde1edb
commit 1ecbe8da65
13 changed files with 72 additions and 23 deletions
+5 -1
View File
@@ -22,10 +22,14 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include "transmission.h"
#define TR_MAX_OPEN_FILES 16 /* That is, real files, not sockets */
+7 -2
View File
@@ -22,7 +22,12 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#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 */
-3
View File
@@ -44,9 +44,6 @@ int vasprintf( char **, const char *, va_list );
#ifndef __AMIGAOS4__
#include <sys/resource.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <assert.h>
#ifdef SYS_BEOS
# define socklen_t uint32_t
+7 -2
View File
@@ -22,6 +22,11 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#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;
+10 -6
View File
@@ -22,10 +22,13 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#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;
}
+5 -2
View File
@@ -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 );
+9 -3
View File
@@ -22,7 +22,12 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#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;
+2 -1
View File
@@ -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 );
+4
View File
@@ -383,6 +383,10 @@ void tr_condClose( tr_cond_t * c )
#if defined( BSD )
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/sysctl.h>
#include <net/route.h>
+6 -1
View File
@@ -22,6 +22,11 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#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 );
}
}
+6 -1
View File
@@ -22,6 +22,11 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#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 );
}
+5
View File
@@ -22,6 +22,11 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "transmission.h"
#include "bencode.h"
#include "bsdqueue.h"
+6 -1
View File
@@ -22,7 +22,12 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#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;