the nice_interfaces_is_private_ip function is not correct
input 192.168.15.69 output false
BUT the result should be true.
the value of sa.in->sin_addr.s_addr is 0x450FA8C0
My environment is OSX ,it is little end.And the following implementation is good for the IP 192.168.15.69:
static gboolean nice_interfaces_is_private_ip (const struct sockaddr *_sa)
{
union {
const struct sockaddr *addr;
const struct sockaddr_in *in;
} sa;
sa.addr = _sa;
if (sa.addr->sa_family == AF_INET) {
/* 10.x.x.x/8 */
if (sa.in->sin_addr.s_addr >> 24 == 0x0A)
return TRUE;
/* 172.16.0.0 - 172.31.255.255 = 172.16.0.0/10 */
if (sa.in->sin_addr.s_addr >> 20 == 0xAC1)
return TRUE;
/* 192.168.x.x/16 */
if ((sa.in->sin_addr.s_addr & 0xFFFF) == 0xA8C0)
return TRUE;
/* 169.254.x.x/16 (for APIPA) */
if (sa.in->sin_addr.s_addr >> 16 == 0xA9FE)
return TRUE;
}
return FALSE;
}