Add g_inet_address_get_native_size (#583205)
authorAlexander Larsson <alexl@redhat.com>
Mon, 25 May 2009 09:33:56 +0000 (11:33 +0200)
committerAlexander Larsson <alexl@redhat.com>
Mon, 25 May 2009 09:33:56 +0000 (11:33 +0200)
This can be used to get the size of g_inet_address_to_bytes().

docs/reference/gio/gio-sections.txt
gio/ginetaddress.c
gio/ginetaddress.h
gio/gio.symbols

index 9d9fe19..03f38ae 100644 (file)
@@ -1415,6 +1415,7 @@ g_inet_address_new_from_bytes
 g_inet_address_new_any
 g_inet_address_new_loopback
 g_inet_address_to_bytes
+g_inet_address_get_native_size
 g_inet_address_to_string
 g_inet_address_get_family
 g_inet_address_get_is_any
index 65accd4..dab2602 100644 (file)
@@ -482,7 +482,8 @@ g_inet_address_to_string (GInetAddress *address)
  * Gets the raw binary address data from @address.
  *
  * Returns: a pointer to an internal array of the bytes in @address,
- * which should not be modified, stored, or freed.
+ * which should not be modified, stored, or freed. The size of this
+ * array can be gotten with g_inet_address_get_native_size().
  *
  * Since: 2.22
  */
@@ -495,6 +496,25 @@ g_inet_address_to_bytes (GInetAddress *address)
 }
 
 /**
+ * g_inet_address_get_native_size:
+ * @address: a #GInetAddress
+ *
+ * Gets the size of the native raw binary address for @address. This
+ * is the size of the data that you get from g_inet_address_to_bytes().
+ *
+ * Returns: the number of bytes used for the native version of @address.
+ *
+ * Since: 2.22
+ */
+gsize
+g_inet_address_get_native_size (GInetAddress *address)
+{
+  if (address->priv->family == AF_INET)
+    return sizeof (address->priv->addr.ipv4);
+  return sizeof (address->priv->addr.ipv6);
+}
+
+/**
  * g_inet_address_get_family:
  * @address: a #GInetAddress
  *
index 3f9e499..9c11efe 100644 (file)
@@ -73,6 +73,8 @@ gchar *               g_inet_address_to_string            (GInetAddress
 
 const guint8 *        g_inet_address_to_bytes             (GInetAddress         *address);
 
+gsize                 g_inet_address_get_native_size      (GInetAddress         *address);
+
 GSocketFamily         g_inet_address_get_family           (GInetAddress         *address);
 
 gboolean              g_inet_address_get_is_any           (GInetAddress         *address);
index 1d9a6a2..89a2e18 100644 (file)
@@ -915,6 +915,7 @@ g_inet_address_get_is_mc_site_local
 g_inet_address_get_is_multicast
 g_inet_address_get_is_site_local
 g_inet_address_to_bytes
+g_inet_address_get_native_size
 g_inet_address_to_string
 #endif
 #endif