From aa78361f24a63b18df292a70a889b1d3c64d5a8e Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 16 Nov 2003 16:33:25 +0000 Subject: Allow /SET dcc_own_ip to be non-local address. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3140 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/dcc/dcc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c index 2fd6317f..8b07b86d 100644 --- a/src/irc/dcc/dcc.c +++ b/src/irc/dcc/dcc.c @@ -245,16 +245,28 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port) GIOChannel *dcc_connect_ip(IPADDR *ip, int port) { IPADDR *own_ip, temp_ip; + const char *own_ip_str; + GIOChannel *handle; - if (*settings_get_str("dcc_own_ip") == '\0') { - own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4; - } else { + own_ip_str = settings_get_str("dcc_own_ip"); + own_ip = NULL; + if (*own_ip_str != '\0') { /* use the specified interface for connecting */ - net_host2ip(settings_get_str("dcc_own_ip"), &temp_ip); - own_ip = &temp_ip; + net_host2ip(own_ip_str, &temp_ip); + if (IPADDR_IS_V6(ip) == IPADDR_IS_V6(&temp_ip)) + own_ip = &temp_ip; } - return net_connect_ip(ip, port, own_ip); + if (own_ip == NULL) + own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4; + + handle = net_connect_ip(ip, port, own_ip); + if (handle == NULL && errno == EADDRNOTAVAIL && own_ip != NULL) { + /* dcc_own_ip is external address */ + own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4; + handle = net_connect_ip(ip, port, own_ip); + } + return handle; } /* Server connected - update server for DCC records that have -- cgit v1.2.3