Commit ce171195 authored by Alexander Larsson's avatar Alexander Larsson

Add g_inet_address_get_native_size (#583205)

This can be used to get the size of g_inet_address_to_bytes().
parent fb70c642
......@@ -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
......
......@@ -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
*/
......@@ -494,6 +495,25 @@ g_inet_address_to_bytes (GInetAddress *address)
return (guint8 *)&address->priv->addr;
}
/**
* 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
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment