$OpenBSD: patch-src_backend_libpq_ip_c,v 1.2 2016/02/13 21:54:28 sthen Exp $

Use the address family from the address, not from the netmask,
since the latter is unreliable. Fixes "samenet"/"samehost".

--- src/backend/libpq/ip.c.orig	Mon Feb  8 21:15:19 2016
+++ src/backend/libpq/ip.c	Fri Feb 12 17:18:09 2016
@@ -423,17 +423,16 @@ run_ifaddr_callback(PgIfAddrCallback callback, void *c
 	/* Check that the mask is valid */
 	if (mask)
 	{
-		if (mask->sa_family != addr->sa_family)
+
+		/* mask->sa_family can be different from addr->sa_family. */
+
+		if (addr->sa_family == AF_INET)
 		{
-			mask = NULL;
-		}
-		else if (mask->sa_family == AF_INET)
-		{
 			if (((struct sockaddr_in *) mask)->sin_addr.s_addr == INADDR_ANY)
 				mask = NULL;
 		}
 #ifdef HAVE_IPV6
-		else if (mask->sa_family == AF_INET6)
+		else if (addr->sa_family == AF_INET6)
 		{
 			if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *) mask)->sin6_addr))
 				mask = NULL;
