From: Wim Taymans Date: Wed, 1 Jul 2009 10:48:38 +0000 (+0200) Subject: netbuffer: add gst_netaddress_to_string X-Git-Tag: RELEASE-0.10.24~82 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ef62de3f0437ff06b4f249e35ecb098e8bb7ec5;p=platform%2Fupstream%2Fgst-plugins-base.git netbuffer: add gst_netaddress_to_string Add function to serialize a net address to a string. API: GstNetAddress::gst_netaddress_to_string() --- diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 9f42217..f96ea7d 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -698,12 +698,20 @@ GstNetType GstNetAddress gst_netbuffer_new -gst_netaddress_get_ip4_address -gst_netaddress_get_ip6_address gst_netaddress_get_net_type + gst_netaddress_set_ip4_address +gst_netaddress_get_ip4_address + gst_netaddress_set_ip6_address +gst_netaddress_get_ip6_address + +gst_netaddress_get_address_bytes +gst_netaddress_set_address_bytes + gst_netaddress_equal + +gst_netaddress_to_string GstNetBufferClass GST_TYPE_NETBUFFER diff --git a/gst-libs/gst/netbuffer/gstnetbuffer.c b/gst-libs/gst/netbuffer/gstnetbuffer.c index 5595546..45db54c 100644 --- a/gst-libs/gst/netbuffer/gstnetbuffer.c +++ b/gst-libs/gst/netbuffer/gstnetbuffer.c @@ -183,7 +183,7 @@ gst_netaddress_set_ip6_address (GstNetAddress * naddr, guint8 address[16], * Returns: the network type stored in @naddr. */ GstNetType -gst_netaddress_get_net_type (GstNetAddress * naddr) +gst_netaddress_get_net_type (const GstNetAddress * naddr) { g_return_val_if_fail (naddr != NULL, GST_NET_TYPE_UNKNOWN); @@ -205,7 +205,7 @@ gst_netaddress_get_net_type (GstNetAddress * naddr) * Returns: TRUE if the address could be retrieved. */ gboolean -gst_netaddress_get_ip4_address (GstNetAddress * naddr, guint32 * address, +gst_netaddress_get_ip4_address (const GstNetAddress * naddr, guint32 * address, guint16 * port) { g_return_val_if_fail (naddr != NULL, FALSE); @@ -238,7 +238,7 @@ gst_netaddress_get_ip4_address (GstNetAddress * naddr, guint32 * address, * Returns: TRUE if the address could be retrieved. */ gboolean -gst_netaddress_get_ip6_address (GstNetAddress * naddr, guint8 address[16], +gst_netaddress_get_ip6_address (const GstNetAddress * naddr, guint8 address[16], guint16 * port) { static guint8 ip4_transition[16] = @@ -278,8 +278,8 @@ gst_netaddress_get_ip6_address (GstNetAddress * naddr, guint8 address[16], * Since: 0.10.22 */ gint -gst_netaddress_get_address_bytes (GstNetAddress * naddr, guint8 address[16], - guint16 * port) +gst_netaddress_get_address_bytes (const GstNetAddress * naddr, + guint8 address[16], guint16 * port) { gint ret = 0; @@ -385,3 +385,63 @@ gst_netaddress_equal (const GstNetAddress * naddr1, } return TRUE; } + +/** + * gst_netaddress_to_string: + * @naddr: a #GstNetAddress + * @dest: destination + * @len: len of @dest + * + * Copies a string representation of @naddr into @dest. Up to @len bytes are + * copied. + * + * Returns: the number of bytes which would be produced if the buffer was large + * enough + * + * Since: 0.10.24 + */ +gint +gst_netaddress_to_string (const GstNetAddress * naddr, gchar * dest, gulong len) +{ + gint result; + + g_return_val_if_fail (naddr != NULL, FALSE); + g_return_val_if_fail (dest != NULL, FALSE); + + switch (naddr->type) { + case GST_NET_TYPE_IP4: + { + guint32 address; + guint16 port; + + gst_netaddress_get_ip4_address (naddr, &address, &port); + address = g_ntohl (address); + + result = g_snprintf (dest, len, "%d.%d.%d.%d:%d", (address >> 24) & 0xff, + (address >> 16) & 0xff, (address >> 8) & 0xff, address & 0xff, + g_ntohs (port)); + break; + } + case GST_NET_TYPE_IP6: + { + guint8 address[16]; + guint16 port; + + gst_netaddress_get_ip6_address (naddr, address, &port); + + result = + g_snprintf (dest, len, "[%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x]:%d", + (address[0] << 8) | address[1], (address[2] << 8) | address[3], + (address[4] << 8) | address[5], (address[6] << 8) | address[7], + (address[8] << 8) | address[9], (address[10] << 8) | address[11], + (address[12] << 8) | address[13], (address[14] << 8) | address[15], + g_ntohs (port)); + break; + } + default: + dest[0] = 0; + result = 0; + break; + } + return result; +} diff --git a/gst-libs/gst/netbuffer/gstnetbuffer.h b/gst-libs/gst/netbuffer/gstnetbuffer.h index f410360..e384943 100644 --- a/gst-libs/gst/netbuffer/gstnetbuffer.h +++ b/gst-libs/gst/netbuffer/gstnetbuffer.h @@ -103,14 +103,16 @@ void gst_netaddress_set_ip6_address (GstNetAddress *naddr, guint8 a gint gst_netaddress_set_address_bytes (GstNetAddress *naddr, GstNetType type, guint8 address[16], guint16 port); -GstNetType gst_netaddress_get_net_type (GstNetAddress *naddr); -gboolean gst_netaddress_get_ip4_address (GstNetAddress *naddr, guint32 *address, guint16 *port); -gboolean gst_netaddress_get_ip6_address (GstNetAddress *naddr, guint8 address[16], guint16 *port); -gint gst_netaddress_get_address_bytes (GstNetAddress *naddr, guint8 address[16], guint16 *port); +GstNetType gst_netaddress_get_net_type (const GstNetAddress *naddr); +gboolean gst_netaddress_get_ip4_address (const GstNetAddress *naddr, guint32 *address, guint16 *port); +gboolean gst_netaddress_get_ip6_address (const GstNetAddress *naddr, guint8 address[16], guint16 *port); +gint gst_netaddress_get_address_bytes (const GstNetAddress *naddr, guint8 address[16], guint16 *port); gboolean gst_netaddress_equal (const GstNetAddress *naddr1, const GstNetAddress *naddr2); +gint gst_netaddress_to_string (const GstNetAddress *naddr, gchar *dest, gulong len); + G_END_DECLS #endif /* __GST_NETBUFFER_H__ */