address-pool: Verify that multicast addresses are used for multicast and vice-versa

This commit is contained in:
Olivier Crête 2013-02-20 14:26:03 -05:00 committed by Wim Taymans
parent d06e68abd1
commit 27a057962c
2 changed files with 12 additions and 6 deletions

View file

@ -183,7 +183,8 @@ gst_rtsp_address_pool_clear (GstRTSPAddressPool * pool)
}
static gboolean
fill_address (const gchar * address, guint16 port, Addr * addr)
fill_address (const gchar * address, guint16 port, Addr * addr,
gboolean is_multicast)
{
GInetAddress *inet;
@ -191,6 +192,11 @@ fill_address (const gchar * address, guint16 port, Addr * addr)
if (inet == NULL)
return FALSE;
if (is_multicast != g_inet_address_get_is_multicast (inet)) {
g_object_unref (inet);
return FALSE;
}
addr->size = g_inet_address_get_native_size (inet);
memcpy (addr->bytes, g_inet_address_to_bytes (inet), addr->size);
g_object_unref (inet);
@ -243,9 +249,9 @@ gst_rtsp_address_pool_add_range (GstRTSPAddressPool * pool,
range = g_slice_new0 (AddrRange);
if (!fill_address (min_address, min_port, &range->min))
if (!fill_address (min_address, min_port, &range->min, (ttl != 0)))
goto invalid;
if (!fill_address (max_address, max_port, &range->max))
if (!fill_address (max_address, max_port, &range->max, (ttl != 0)))
goto invalid;
if (range->min.size != range->max.size)
@ -603,7 +609,7 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
result = NULL;
addr = NULL;
if (!fill_address (address, port, &input_addr)) {
if (!fill_address (address, port, &input_addr, (ttl != 0))) {
GST_ERROR_OBJECT (pool, "invalid address %s", address);
return NULL;
}

View file

@ -78,14 +78,14 @@ GST_START_TEST (test_pool)
* starting with even port
*/
fail_unless (gst_rtsp_address_pool_add_range (pool,
"2001:DB8::1", "2001:DB8::1", 5001, 5003, 1));
"FF11:DB8::1", "FF11:DB8::1", 5001, 5003, 1));
addr = gst_rtsp_address_pool_acquire_address (pool,
GST_RTSP_ADDRESS_FLAG_IPV6 | GST_RTSP_ADDRESS_FLAG_EVEN_PORT |
GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
fail_unless (addr != NULL);
fail_unless (addr->port == 5002);
fail_unless (!g_ascii_strcasecmp (addr->address, "2001:DB8::1"));
fail_unless (!g_ascii_strcasecmp (addr->address, "FF11:DB8::1"));
/* Will fail becuse there is only one IPv6 address left */
addr2 = gst_rtsp_address_pool_acquire_address (pool,