Could you please try attached patch? It uses AF_UNSPEC in getaddrinfo()
hints whenever host string is non-empty and retries getaddrinfo() with
AF_UNSPEC if AF_INET6 fails for empty host string.

Handling Windows XP with IPv6 support will be more tricky. What might
work would be to move the attempt to set IPV6_V6ONLY earlier, before
getaddrinfo() is called, and also use AF_UNSPEC if setting IPV6_V6ONLY
to 0 failed.

                                                       Michal Kubecek

>From d79f62ef71764e233cfa24a1f78afd9e480f19a4 Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkube...@suse.cz>
Date: Wed, 19 Nov 2014 12:40:53 +0100
Subject: [PATCH] Fix server address resolution on systems without IPv6
 support.

We should only use AF_INET6 in getaddrinfo() hints if host string is
empty (so that we are listening on a wildcard address. If host string is
non-empty, let getaddrinfo() decide suitable address family.

As a bonus, this prevents server from binding to v6-mapped address if an
IPv4 address is used for RemotBindAddress configuration directive.
---
 src/remote/inet.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/remote/inet.cpp b/src/remote/inet.cpp
index 3696ef7..7b6c5b5 100644
--- a/src/remote/inet.cpp
+++ b/src/remote/inet.cpp
@@ -869,7 +869,7 @@ rem_port* INET_connect(const TEXT* name,
 	// Prepare hints
 	struct addrinfo gai_hints;
 	memset(&gai_hints, 0, sizeof(gai_hints));
-	gai_hints.ai_family = (packet ? AF_UNSPEC : AF_INET6);
+	gai_hints.ai_family = ((packet || host.hasData()) ? AF_UNSPEC : AF_INET6);
 	gai_hints.ai_socktype = SOCK_STREAM;
 
 #ifndef WIN_NT
@@ -884,6 +884,12 @@ rem_port* INET_connect(const TEXT* name,
 	struct addrinfo* gai_result;
 	int n = getaddrinfo(host_str, protocol.c_str(), &gai_hints, &gai_result);
 
+	if (n && (gai_hints.ai_family == AF_INET6))
+	{
+		// Might be on a system without IPv6 support, try IPv4
+		gai_hints.ai_family = AF_UNSPEC;
+		n = getaddrinfo(host_str, protocol.c_str(), &gai_hints, &gai_result);
+	}
 	if (n && (protocol == FB_SERVICE_NAME))
 	{
 		// Try hard-wired translation of "gds_db" to "3050"
-- 
1.8.4.5

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to