From: Patrik Weiskircher Date: Wed, 22 Sep 2004 17:50:49 +0000 (+0000) Subject: When using silc_net_create_connection[_async], and your system can X-Git-Tag: silc.server.0.9.19~62 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=e197ceb77febcd04fa82a220a743743fe52a39bb;p=silc.git When using silc_net_create_connection[_async], and your system can create IPv6 sockets, it will try to connect to the IPv6 host. Now it tries to connect to an IPv4 host if IPv6 fails. --- diff --git a/CHANGES b/CHANGES index 045ff608..36e1d6d4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +Wed Sep 22 19:46:32 CEST 2004 Patrik Weiskircher + + * When using silc_net_create_connection[_async], and your system can + create IPv6 sockets, it will try to connect to the IPv6 host. Now it + tries to connect to an IPv4 host if IPv6 fails. Affected file + lib/silcutil/unix/silcunixnet.c + Fri Jun 18 19:26:58 CEST 2004 Pekka Riikonen * Check for valid route when receiving packet from router and diff --git a/lib/silcutil/unix/silcunixnet.c b/lib/silcutil/unix/silcunixnet.c index b753ac51..d2e52e93 100644 --- a/lib/silcutil/unix/silcunixnet.c +++ b/lib/silcutil/unix/silcunixnet.c @@ -197,6 +197,14 @@ int silc_net_create_connection(const char *local_ip, int port, /* Connect to the host */ rval = connect(sock, &desthost.sa, SIZEOF_SOCKADDR(desthost)); if (rval < 0) { + /* retry using an IPv4 adress, if IPv6 didn't work */ + if (prefer_ipv6 && silc_net_is_ip6(ip_addr)) { + shutdown(sock, 2); + close(sock); + + prefer_ipv6 = FALSE; + goto retry; + } SILC_LOG_ERROR(("Cannot connect to remote host: %s", strerror(errno))); shutdown(sock, 2); close(sock); @@ -272,6 +280,15 @@ int silc_net_create_connection_async(const char *local_ip, int port, rval = connect(sock, &desthost.sa, SIZEOF_SOCKADDR(desthost)); if (rval < 0) { if (errno != EINPROGRESS) { + /* retry using an IPv4 adress, if IPv6 didn't work */ + if (prefer_ipv6 && silc_net_is_ip6(ip_addr)) { + shutdown(sock, 2); + close(sock); + + prefer_ipv6 = FALSE; + goto retry; + } + SILC_LOG_ERROR(("Cannot connect to remote host: %s", strerror(errno))); shutdown(sock, 2); close(sock);