aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2008-04-06 16:34:25 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2008-04-06 16:34:25 +0100
commitaefaac3a5d44537bdf804d1f42e491cc2b931889 (patch)
tree9fa2b9efc24fd39452db57836f38dc12c8f83398
parentaa311173a85020bcbbbf61135a5451e171d422f5 (diff)
Added ClientInterface configuration option to make BitlBee bind() to a
specific interface before connecting to a remote host.
-rw-r--r--bitlbee.c4
-rw-r--r--bitlbee.conf7
-rw-r--r--conf.c14
-rw-r--r--conf.h2
-rw-r--r--lib/proxy.c11
5 files changed, 31 insertions, 7 deletions
diff --git a/bitlbee.c b/bitlbee.c
index 230b8ce8..17431546 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -53,11 +53,11 @@ int bitlbee_daemon_init()
#endif
;
- i = getaddrinfo( global.conf->iface, global.conf->port, &hints, &addrinfo_bind );
+ i = getaddrinfo( global.conf->iface_in, global.conf->port, &hints, &addrinfo_bind );
if( i )
{
log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s",
- global.conf->iface, gai_strerror(i) );
+ global.conf->iface_in, gai_strerror(i) );
return -1;
}
diff --git a/bitlbee.conf b/bitlbee.conf
index 99e8106d..c03a564f 100644
--- a/bitlbee.conf
+++ b/bitlbee.conf
@@ -34,6 +34,13 @@
# DaemonInterface = 0.0.0.0
# DaemonPort = 6667
+## ClientInterface:
+##
+## If for any reason, you want BitlBee to use a specific address/interface
+## for outgoing traffic (IM connections, HTTP(S), etc.), set it here.
+##
+# ClientInterface = 0.0.0.0
+
## AuthMode
##
## Open -- Accept connections from anyone, use NickServ for user authentication.
diff --git a/conf.c b/conf.c
index 339af618..8d6291ff 100644
--- a/conf.c
+++ b/conf.c
@@ -44,7 +44,8 @@ conf_t *conf_load( int argc, char *argv[] )
conf = g_new0( conf_t, 1 );
- conf->iface = NULL;
+ conf->iface_in = NULL;
+ conf->iface_out = NULL;
conf->port = g_strdup( "6667" );
conf->nofork = 0;
conf->verbose = 0;
@@ -81,7 +82,7 @@ conf_t *conf_load( int argc, char *argv[] )
{
if( opt == 'i' )
{
- conf->iface = g_strdup( optarg );
+ conf->iface_in = g_strdup( optarg );
}
else if( opt == 'p' )
{
@@ -201,14 +202,19 @@ static int conf_loadini( conf_t *conf, char *file )
}
else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 )
{
- g_free( conf->iface );
- conf->iface = g_strdup( ini->value );
+ g_free( conf->iface_in );
+ conf->iface_in = g_strdup( ini->value );
}
else if( g_strcasecmp( ini->key, "daemonport" ) == 0 )
{
g_free( conf->port );
conf->port = g_strdup( ini->value );
}
+ else if( g_strcasecmp( ini->key, "clientinterface" ) == 0 )
+ {
+ g_free( conf->iface_out );
+ conf->iface_out = g_strdup( ini->value );
+ }
else if( g_strcasecmp( ini->key, "authmode" ) == 0 )
{
if( g_strcasecmp( ini->value, "registered" ) == 0 )
diff --git a/conf.h b/conf.h
index d21ec577..c41fd096 100644
--- a/conf.h
+++ b/conf.h
@@ -31,7 +31,7 @@ typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } au
typedef struct conf
{
- char *iface;
+ char *iface_in, *iface_out;
char *port;
int nofork;
int verbose;
diff --git a/lib/proxy.c b/lib/proxy.c
index 53b89d64..91493557 100644
--- a/lib/proxy.c
+++ b/lib/proxy.c
@@ -113,6 +113,7 @@ static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition
static int proxy_connect_none(const char *host, unsigned short port, struct PHB *phb)
{
struct sockaddr_in *sin;
+ struct sockaddr_in me;
int fd = -1;
if (!(sin = gaim_gethostbyname(host, port))) {
@@ -127,6 +128,16 @@ static int proxy_connect_none(const char *host, unsigned short port, struct PHB
sock_make_nonblocking(fd);
+ if( global.conf->iface_out )
+ {
+ me.sin_family = AF_INET;
+ me.sin_port = 0;
+ me.sin_addr.s_addr = inet_addr( global.conf->iface_out );
+
+ if( bind( fd, (struct sockaddr *) &me, sizeof( me ) ) != 0 )
+ event_debug( "bind( %d, \"%s\" ) failure\n", fd, global.conf->iface_out );
+ }
+
event_debug("proxy_connect_none( \"%s\", %d ) = %d\n", host, port, fd);
if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0 && !sockerr_again()) {