* 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);
* 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);
* 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] =
* 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;
}
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;
+}
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__ */