mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 23:46:15 +01:00
Merge branch 'fix/support-for-systems-without-ipv6' into 'master'
ginetaddress: Handle systems without IPv6 support See merge request GNOME/glib!1853
This commit is contained in:
commit
c5eec23ee2
@ -36,7 +36,9 @@ struct _GInetAddressPrivate
|
||||
GSocketFamily family;
|
||||
union {
|
||||
struct in_addr ipv4;
|
||||
#ifdef HAVE_IPV6
|
||||
struct in6_addr ipv6;
|
||||
#endif
|
||||
} addr;
|
||||
};
|
||||
|
||||
@ -99,10 +101,16 @@ g_inet_address_set_property (GObject *object,
|
||||
break;
|
||||
|
||||
case PROP_BYTES:
|
||||
#ifdef HAVE_IPV6
|
||||
memcpy (&address->priv->addr, g_value_get_pointer (value),
|
||||
address->priv->family == AF_INET ?
|
||||
sizeof (address->priv->addr.ipv4) :
|
||||
sizeof (address->priv->addr.ipv6));
|
||||
#else
|
||||
g_assert (address->priv->family == AF_INET);
|
||||
memcpy (&address->priv->addr, g_value_get_pointer (value),
|
||||
sizeof (address->priv->addr.ipv4));
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -385,7 +393,9 @@ GInetAddress *
|
||||
g_inet_address_new_from_string (const gchar *string)
|
||||
{
|
||||
struct in_addr in_addr;
|
||||
#ifdef HAVE_IPV6
|
||||
struct in6_addr in6_addr;
|
||||
#endif
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
@ -397,8 +407,10 @@ g_inet_address_new_from_string (const gchar *string)
|
||||
|
||||
if (inet_pton (AF_INET, string, &in_addr) > 0)
|
||||
return g_inet_address_new_from_bytes ((guint8 *)&in_addr, AF_INET);
|
||||
#ifdef HAVE_IPV6
|
||||
else if (inet_pton (AF_INET6, string, &in6_addr) > 0)
|
||||
return g_inet_address_new_from_bytes ((guint8 *)&in6_addr, AF_INET6);
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -455,7 +467,11 @@ g_inet_address_new_loopback (GSocketFamily family)
|
||||
return g_inet_address_new_from_bytes (addr, family);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return g_inet_address_new_from_bytes (in6addr_loopback.s6_addr, family);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,7 +499,11 @@ g_inet_address_new_any (GSocketFamily family)
|
||||
return g_inet_address_new_from_bytes (addr, family);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return g_inet_address_new_from_bytes (in6addr_any.s6_addr, family);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -506,11 +526,19 @@ g_inet_address_to_string (GInetAddress *address)
|
||||
g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
|
||||
|
||||
if (address->priv->family == AF_INET)
|
||||
inet_ntop (AF_INET, &address->priv->addr.ipv4, buffer, sizeof (buffer));
|
||||
{
|
||||
inet_ntop (AF_INET, &address->priv->addr.ipv4, buffer, sizeof (buffer));
|
||||
return g_strdup (buffer);
|
||||
}
|
||||
else
|
||||
inet_ntop (AF_INET6, &address->priv->addr.ipv6, buffer, sizeof (buffer));
|
||||
|
||||
return g_strdup (buffer);
|
||||
{
|
||||
#ifdef HAVE_IPV6
|
||||
inet_ntop (AF_INET6, &address->priv->addr.ipv6, buffer, sizeof (buffer));
|
||||
return g_strdup (buffer);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,7 +577,11 @@ g_inet_address_get_native_size (GInetAddress *address)
|
||||
{
|
||||
if (address->priv->family == AF_INET)
|
||||
return sizeof (address->priv->addr.ipv4);
|
||||
#ifdef HAVE_IPV6
|
||||
return sizeof (address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -592,7 +624,11 @@ g_inet_address_get_is_any (GInetAddress *address)
|
||||
return addr4 == INADDR_ANY;
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_UNSPECIFIED (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -618,7 +654,11 @@ g_inet_address_get_is_loopback (GInetAddress *address)
|
||||
return ((addr4 & 0xff000000) == 0x7f000000);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_LOOPBACK (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -646,7 +686,11 @@ g_inet_address_get_is_link_local (GInetAddress *address)
|
||||
return ((addr4 & 0xffff0000) == 0xa9fe0000);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_LINKLOCAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -677,7 +721,11 @@ g_inet_address_get_is_site_local (GInetAddress *address)
|
||||
(addr4 & 0xffff0000) == 0xc0a80000);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_SITELOCAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -702,7 +750,11 @@ g_inet_address_get_is_multicast (GInetAddress *address)
|
||||
return IN_MULTICAST (addr4);
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_MULTICAST (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -723,7 +775,11 @@ g_inet_address_get_is_mc_global (GInetAddress *address)
|
||||
if (address->priv->family == AF_INET)
|
||||
return FALSE;
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_MC_GLOBAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -744,7 +800,11 @@ g_inet_address_get_is_mc_link_local (GInetAddress *address)
|
||||
if (address->priv->family == AF_INET)
|
||||
return FALSE;
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_MC_LINKLOCAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -765,7 +825,11 @@ g_inet_address_get_is_mc_node_local (GInetAddress *address)
|
||||
if (address->priv->family == AF_INET)
|
||||
return FALSE;
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_MC_NODELOCAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -786,7 +850,11 @@ g_inet_address_get_is_mc_org_local (GInetAddress *address)
|
||||
if (address->priv->family == AF_INET)
|
||||
return FALSE;
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_MC_ORGLOCAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -807,7 +875,11 @@ g_inet_address_get_is_mc_site_local (GInetAddress *address)
|
||||
if (address->priv->family == AF_INET)
|
||||
return FALSE;
|
||||
else
|
||||
#ifdef HAVE_IPV6
|
||||
return IN6_IS_ADDR_MC_SITELOCAL (&address->priv->addr.ipv6);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1757,6 +1757,13 @@ foreach d : inet_defines
|
||||
glibconfig_conf.set(d[1], val)
|
||||
endforeach
|
||||
|
||||
if host_system == 'windows'
|
||||
have_ipv6 = true
|
||||
else
|
||||
have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
|
||||
endif
|
||||
glib_conf.set('HAVE_IPV6', have_ipv6)
|
||||
|
||||
# We need to decide at configure time if GLib will use real atomic
|
||||
# operations ("lock free") or emulated ones with a mutex. This is
|
||||
# because we must put this information in glibconfig.h so we know if
|
||||
|
Loading…
Reference in New Issue
Block a user