projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
updates.
[silc.git]
/
lib
/
silcutil
/
unix
/
silcunixnet.c
diff --git
a/lib/silcutil/unix/silcunixnet.c
b/lib/silcutil/unix/silcunixnet.c
index d1f6384ce7aa3d7f1158fd3f164694fc7b1e15ea..48b17e16c6a16a1545797b63bf0b9361c4d09360 100644
(file)
--- a/
lib/silcutil/unix/silcunixnet.c
+++ b/
lib/silcutil/unix/silcunixnet.c
@@
-155,11
+155,13
@@
int silc_net_create_connection(const char *local_ip, int port,
int sock, rval;
char ip_addr[64];
SilcSockaddr desthost;
int sock, rval;
char ip_addr[64];
SilcSockaddr desthost;
+ bool prefer_ipv6 = TRUE;
SILC_LOG_DEBUG(("Creating connection to host %s port %d", host, port));
/* Do host lookup */
SILC_LOG_DEBUG(("Creating connection to host %s port %d", host, port));
/* Do host lookup */
- if (!silc_net_gethostbyname(host, ip_addr, sizeof(ip_addr))) {
+ retry:
+ if (!silc_net_gethostbyname(host, prefer_ipv6, ip_addr, sizeof(ip_addr))) {
SILC_LOG_ERROR(("Network (%s) unreachable: could not resolve the "
"IP address", host));
return -1;
SILC_LOG_ERROR(("Network (%s) unreachable: could not resolve the "
"IP address", host));
return -1;
@@
-172,6
+174,13
@@
int silc_net_create_connection(const char *local_ip, int port,
/* Create the connection socket */
sock = socket(desthost.sin.sin_family, SOCK_STREAM, 0);
if (sock < 0) {
/* Create the connection socket */
sock = socket(desthost.sin.sin_family, SOCK_STREAM, 0);
if (sock < 0) {
+ /* If address is IPv6, then fallback to IPv4 and see whether we can do
+ better with that on socket creation. */
+ if (prefer_ipv6 && silc_net_is_ip6(ip_addr)) {
+ prefer_ipv6 = FALSE;
+ goto retry;
+ }
+
SILC_LOG_ERROR(("Cannot create socket: %s", strerror(errno)));
return -1;
}
SILC_LOG_ERROR(("Cannot create socket: %s", strerror(errno)));
return -1;
}
@@
-216,12
+225,14
@@
int silc_net_create_connection_async(const char *local_ip, int port,
int sock, rval;
char ip_addr[64];
SilcSockaddr desthost;
int sock, rval;
char ip_addr[64];
SilcSockaddr desthost;
+ bool prefer_ipv6 = TRUE;
SILC_LOG_DEBUG(("Creating connection (async) to host %s port %d",
host, port));
/* Do host lookup */
SILC_LOG_DEBUG(("Creating connection (async) to host %s port %d",
host, port));
/* Do host lookup */
- if (!silc_net_gethostbyname(host, ip_addr, sizeof(ip_addr))) {
+ retry:
+ if (!silc_net_gethostbyname(host, prefer_ipv6, ip_addr, sizeof(ip_addr))) {
SILC_LOG_ERROR(("Network (%s) unreachable: could not resolve the "
"IP address", host));
return -1;
SILC_LOG_ERROR(("Network (%s) unreachable: could not resolve the "
"IP address", host));
return -1;
@@
-234,6
+245,13
@@
int silc_net_create_connection_async(const char *local_ip, int port,
/* Create the connection socket */
sock = socket(desthost.sin.sin_family, SOCK_STREAM, 0);
if (sock < 0) {
/* Create the connection socket */
sock = socket(desthost.sin.sin_family, SOCK_STREAM, 0);
if (sock < 0) {
+ /* If address is IPv6, then fallback to IPv4 and see whether we can do
+ better with that on socket creation. */
+ if (prefer_ipv6 && silc_net_is_ip6(ip_addr)) {
+ prefer_ipv6 = FALSE;
+ goto retry;
+ }
+
SILC_LOG_ERROR(("Cannot create socket: %s", strerror(errno)));
return -1;
}
SILC_LOG_ERROR(("Cannot create socket: %s", strerror(errno)));
return -1;
}