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