diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index a79be0596..13c7cc59b 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -1486,6 +1486,7 @@ g_inet_address_new_from_string g_inet_address_new_from_bytes g_inet_address_new_any g_inet_address_new_loopback +g_inet_address_equal g_inet_address_to_bytes g_inet_address_get_native_size g_inet_address_to_string diff --git a/gio/ginetaddress.c b/gio/ginetaddress.c index 260c7752d..743ac0682 100644 --- a/gio/ginetaddress.c +++ b/gio/ginetaddress.c @@ -866,3 +866,32 @@ g_inet_address_get_is_mc_site_local (GInetAddress *address) else return IN6_IS_ADDR_MC_SITELOCAL (&address->priv->addr.ipv6); } + +/** + * g_inet_address_equal: + * @address: A #GInetAddress. + * @other_address: Another #GInetAddress. + * + * Checks if two #GInetAddress instances are equal, e.g. the same address. + * + * Returns: %TRUE if @address and @other_address are equal, %FALSE otherwise. + * + * Since: 2.30 + */ +gboolean +g_inet_address_equal (GInetAddress *address, + GInetAddress *other_address) +{ + g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE); + g_return_val_if_fail (G_IS_INET_ADDRESS (other_address), FALSE); + + if (g_inet_address_get_family (address) != g_inet_address_get_family (other_address)) + return FALSE; + + if (memcmp (g_inet_address_to_bytes (address), + g_inet_address_to_bytes (other_address), + g_inet_address_get_native_size (address)) != 0) + return FALSE; + + return TRUE; +} diff --git a/gio/ginetaddress.h b/gio/ginetaddress.h index 9c11efefd..d523cd654 100644 --- a/gio/ginetaddress.h +++ b/gio/ginetaddress.h @@ -69,6 +69,9 @@ GInetAddress * g_inet_address_new_loopback (GSocketFamily GInetAddress * g_inet_address_new_any (GSocketFamily family); +gboolean g_inet_address_equal (GInetAddress *address, + GInetAddress *other_address); + gchar * g_inet_address_to_string (GInetAddress *address); const guint8 * g_inet_address_to_bytes (GInetAddress *address); diff --git a/gio/gio.symbols b/gio/gio.symbols index 64275aebc..68ed9a3f3 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -1123,6 +1123,7 @@ g_inet_address_get_is_site_local g_inet_address_to_bytes g_inet_address_get_native_size g_inet_address_to_string +g_inet_address_equal #endif #endif