diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c index 9451bb6e..8ca8f8bc 100644 --- a/src/irc/dcc/dcc-chat.c +++ b/src/irc/dcc/dcc-chat.c @@ -30,7 +30,6 @@ #include "irc-servers.h" #include "irc-queries.h" -#include "servers-setup.h" #include "masks.h" #include "dcc-chat.h" @@ -360,8 +359,6 @@ static void sig_chat_connected(CHAT_DCC_REC *dcc) static void dcc_chat_connect(CHAT_DCC_REC *dcc) { - IPADDR *own_ip; - g_return_if_fail(IS_DCC_CHAT(dcc)); if (dcc->addrstr[0] == '\0' || @@ -370,8 +367,7 @@ static void dcc_chat_connect(CHAT_DCC_REC *dcc) return; } - own_ip = IPADDR_IS_V6(&dcc->addr) ? source_host_ip6 : source_host_ip4; - dcc->handle = net_connect_ip(&dcc->addr, dcc->port, own_ip); + dcc->handle = dcc_connect_ip(&dcc->addr, dcc->port); if (dcc->handle != NULL) { dcc->tagconn = g_input_add(dcc->handle, G_INPUT_WRITE | G_INPUT_READ, diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c index 4afb59be..39b368f6 100644 --- a/src/irc/dcc/dcc-get.c +++ b/src/irc/dcc/dcc-get.c @@ -26,7 +26,6 @@ #include "settings.h" #include "irc-servers.h" -#include "servers-setup.h" #include "dcc-get.h" @@ -214,15 +213,12 @@ static void sig_dccget_connected(GET_DCC_REC *dcc) void dcc_get_connect(GET_DCC_REC *dcc) { - IPADDR *own_ip; - if (dcc->get_type == DCC_GET_DEFAULT) { dcc->get_type = settings_get_bool("dcc_autorename") ? DCC_GET_RENAME : DCC_GET_OVERWRITE; } - own_ip = IPADDR_IS_V6(&dcc->addr) ? source_host_ip6 : source_host_ip4; - dcc->handle = net_connect_ip(&dcc->addr, dcc->port, own_ip); + dcc->handle = dcc_connect_ip(&dcc->addr, dcc->port); if (dcc->handle != NULL) { dcc->tagconn = g_input_add(dcc->handle, diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c index b586a51e..37bc7854 100644 --- a/src/irc/dcc/dcc.c +++ b/src/irc/dcc/dcc.c @@ -29,6 +29,7 @@ #include "levels.h" #include "irc-servers.h" +#include "servers-setup.h" #include "dcc-chat.h" #include "dcc-get.h" @@ -199,7 +200,7 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port) int first, last; if (net_getsockname(iface, ip, NULL) == -1) - return NULL; + return NULL; /* get first port */ dcc_port = settings_get_str("dcc_port"); @@ -233,6 +234,22 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port) return NULL; } +/* Connect to specified IP address using the correct own_ip. */ +GIOChannel *dcc_connect_ip(IPADDR *ip, int port) +{ + IPADDR *own_ip, temp_ip; + + if (*settings_get_str("dcc_own_ip") == '\0') { + own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4; + } else { + /* use the specified interface for connecting */ + net_host2ip(settings_get_str("dcc_own_ip"), &temp_ip); + own_ip = &temp_ip; + } + + return net_connect_ip(ip, port, own_ip); +} + /* Server connected - update server for DCC records that have the same server tag */ static void sig_server_connected(IRC_SERVER_REC *server) diff --git a/src/irc/dcc/dcc.h b/src/irc/dcc/dcc.h index 57a0e2dc..5a4c9e23 100644 --- a/src/irc/dcc/dcc.h +++ b/src/irc/dcc/dcc.h @@ -49,6 +49,8 @@ void dcc_str2ip(const char *str, IPADDR *ip); /* Start listening for incoming connections */ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port); +/* Connect to specified IP address using the correct own_ip. */ +GIOChannel *dcc_connect_ip(IPADDR *ip, int port); /* Close DCC - sends "dcc closed" signal and calls dcc_destroy() */ void dcc_close(DCC_REC *dcc);