mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
netbuffer: add gst_netaddress_to_string
Add function to serialize a net address to a string. API: GstNetAddress::gst_netaddress_to_string()
This commit is contained in:
parent
e8598d24e5
commit
8ef62de3f0
3 changed files with 81 additions and 11 deletions
|
@ -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
|
||||
<SUBSECTION Standard>
|
||||
GstNetBufferClass
|
||||
GST_TYPE_NETBUFFER
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in a new issue