GInetAddress: add equal() method
authorDavid Zeuthen <davidz@redhat.com>
Thu, 14 Apr 2011 15:27:57 +0000 (11:27 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Thu, 14 Apr 2011 16:46:46 +0000 (12:46 -0400)
This is needed in the fix for

https://bugzilla.gnome.org/show_bug.cgi?id=631379

Signed-off-by: David Zeuthen <davidz@redhat.com>
docs/reference/gio/gio-sections.txt
gio/ginetaddress.c
gio/ginetaddress.h
gio/gio.symbols

index a79be05..13c7cc5 100644 (file)
@@ -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
index 260c775..743ac06 100644 (file)
@@ -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;
+}
index 9c11efe..d523cd6 100644 (file)
@@ -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);
index 64275ae..68ed9a3 100644 (file)
@@ -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