Add g_inet_address_get_native_size (#583205)

This can be used to get the size of g_inet_address_to_bytes().
This commit is contained in:
Alexander Larsson 2009-05-25 11:33:56 +02:00
parent fb70c6420b
commit ce171195d9
4 changed files with 25 additions and 1 deletions

View 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

View 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
*/
@ -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

View 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);

View 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