diff options
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | gst-libs/gst/netbuffer/gstnetbuffer.c | 97 | ||||
-rw-r--r-- | gst-libs/gst/netbuffer/gstnetbuffer.h | 25 |
3 files changed, 124 insertions, 15 deletions
@@ -1,3 +1,20 @@ +2008-12-18 Wim Taymans <wim.taymans@collabora.co.uk> + + Patch by: Andrew Feren <acferen at yahoo dot com> + + * gst-libs/gst/netbuffer/gstnetbuffer.c: + (gst_netaddress_get_ip4_address), (gst_netaddress_get_ip6_address), + (gst_netaddress_get_address_bytes), + (gst_netaddress_set_address_bytes): + * gst-libs/gst/netbuffer/gstnetbuffer.h: + Make gst_netaddress_get_ip4_address fail for v6 addresses. + Make gst_netaddress_get_ip6_address either fail or return the v4 + address as a transitional v6 address. + Add two convenience functions: + API: gst_netaddress_get_address_bytes() + API: gst_netaddress_set_address_bytes() + Fixes #564896. + 2008-12-17 Stefan Kost <ensonic@users.sf.net> * gst/adder/Makefile.am: diff --git a/gst-libs/gst/netbuffer/gstnetbuffer.c b/gst-libs/gst/netbuffer/gstnetbuffer.c index 964d1b84..2348594a 100644 --- a/gst-libs/gst/netbuffer/gstnetbuffer.c +++ b/gst-libs/gst/netbuffer/gstnetbuffer.c @@ -190,7 +190,8 @@ gst_netaddress_get_net_type (GstNetAddress * naddr) * @address: a location to store the address. * @port: a location to store the port. * - * Get the IPv4 address stored in @naddr into @address. + * Get the IPv4 address stored in @naddr into @address. This function requires + * that the address type of @naddr is of type #GST_NET_TYPE_IP4. * * Returns: TRUE if the address could be retrieved. */ @@ -200,7 +201,7 @@ gst_netaddress_get_ip4_address (GstNetAddress * naddr, guint32 * address, { g_return_val_if_fail (naddr != NULL, FALSE); - if (naddr->type == GST_NET_TYPE_UNKNOWN) + if (naddr->type == GST_NET_TYPE_UNKNOWN || naddr->type == GST_NET_TYPE_IP6) return FALSE; if (address) @@ -219,19 +220,30 @@ gst_netaddress_get_ip4_address (GstNetAddress * naddr, guint32 * address, * * Get the IPv6 address stored in @naddr into @address. * + * If @naddr is of type GST_NET_TYPE_IP4, the transitional IP6 address is + * returned. + * * Returns: TRUE if the address could be retrieved. */ gboolean gst_netaddress_get_ip6_address (GstNetAddress * naddr, guint8 address[16], guint16 * port) { + static guint8 ip4_transition[16] = + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF }; g_return_val_if_fail (naddr != NULL, FALSE); if (naddr->type == GST_NET_TYPE_UNKNOWN) return FALSE; - if (address) - memcpy (address, naddr->address.ip6, 16); + if (address) { + if (naddr->type == GST_NET_TYPE_IP6) { + memcpy (address, naddr->address.ip6, 16); + } else { /* naddr->type == GST_NET_TYPE_IP4 */ + memcpy (address, ip4_transition, 12); + memcpy (address + 12, (guint8 *) & (naddr->address.ip4), 4); + } + } if (port) *port = naddr->port; @@ -239,6 +251,83 @@ gst_netaddress_get_ip6_address (GstNetAddress * naddr, guint8 address[16], } /** + * gst_netaddress_get_address_bytes: + * @naddr: a network address + * @address: a location to store the result. + * @port: a location to store the port. + * + * Get just the address bytes stored in @naddr into @address. + * + * Returns: number of bytes actually copied + * + * Since: 0.10.22 + */ +gint +gst_netaddress_get_address_bytes (GstNetAddress * naddr, guint8 address[16], + guint16 * port) +{ + gint ret = 0; + + g_return_val_if_fail (naddr != NULL, FALSE); + + if (naddr->type == GST_NET_TYPE_UNKNOWN) + return 0; + + if (address) { + if (naddr->type == GST_NET_TYPE_IP6) { + memcpy (address, naddr->address.ip6, 16); + ret = 16; + } else { /* naddr->type == GST_NET_TYPE_IP4 */ + memcpy (address, (guint8 *) & (naddr->address.ip4), 4); + ret = 4; + } + } + if (port) + *port = naddr->port; + + return ret; +} + +/** + * gst_netaddress_set_address_bytes: + * @naddr: a network address + * @address: a location to store the result. + * @port: a location to store the port. + * + * Set just the address bytes stored in @naddr into @address. + * + * Returns: number of bytes actually copied + * + * Since: 0.10.22 + */ +gint +gst_netaddress_set_address_bytes (GstNetAddress * naddr, GstNetType type, + guint8 address[16], guint16 port) +{ + gint len = 0; + + g_return_val_if_fail (naddr != NULL, 0); + + naddr->type = type; + switch (naddr->type) { + case GST_NET_TYPE_UNKNOWN: + case GST_NET_TYPE_IP6: + len = 16; + memcpy (naddr->address.ip6, address, 16); + break; + case GST_NET_TYPE_IP4: + len = 4; + memcpy ((guint8 *) & (naddr->address.ip4), address, 4); + break; + } + + if (port) + naddr->port = port; + + return len; +} + +/** * gst_netaddress_equal: * @naddr1: The first #GstNetAddress * @naddr2: The second #GstNetAddress diff --git a/gst-libs/gst/netbuffer/gstnetbuffer.h b/gst-libs/gst/netbuffer/gstnetbuffer.h index 4910ea37..f4103605 100644 --- a/gst-libs/gst/netbuffer/gstnetbuffer.h +++ b/gst-libs/gst/netbuffer/gstnetbuffer.h @@ -93,20 +93,23 @@ struct _GstNetBufferClass { }; /* creating buffers */ -GType gst_netbuffer_get_type (void); +GType gst_netbuffer_get_type (void); -GstNetBuffer* gst_netbuffer_new (void); +GstNetBuffer* gst_netbuffer_new (void); /* address operations */ -void gst_netaddress_set_ip4_address (GstNetAddress *naddr, guint32 address, guint16 port); -void gst_netaddress_set_ip6_address (GstNetAddress *naddr, 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); - -gboolean gst_netaddress_equal (const GstNetAddress *naddr1, - const GstNetAddress *naddr2); +void gst_netaddress_set_ip4_address (GstNetAddress *naddr, guint32 address, guint16 port); +void gst_netaddress_set_ip6_address (GstNetAddress *naddr, guint8 address[16], guint16 port); +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); + +gboolean gst_netaddress_equal (const GstNetAddress *naddr1, + const GstNetAddress *naddr2); G_END_DECLS |