Hi, So after the issue with the overlapping memcpy got resolved I gave this a shot. Currently this feature is broken. The reason is that in netmask sockaddrs, sa_family can be different from the (correct) family encoded in the address's sockaddr (it can be zero instead of AF_INET).
I've tested a bit the following diff, both for samenet and samehost, and it seems to give the expected result. I will go back at the code to be sure it does what is expected, though, I'm posting it here so that people can try cases I did not think of. If the patch is deemed good after more reviews and testing, is that something we'd want for 5.7? I'll push it upstream anyway. $OpenBSD$ Use the address family from the address, not from the netmask, since the latter is unreliable. --- src/backend/libpq/ip.c.orig Mon Feb 16 23:36:42 2015 +++ src/backend/libpq/ip.c Mon Feb 16 23:47:56 2015 @@ -496,17 +496,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; -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE