address-pool: fix address increment

Use a guint instead of guint8 to increment the address. It's still not
completely correct because a guint might not be able to hold the complete
address range, but that's an enhacement for later.
Add unit test to test improved behaviour.

https://bugzilla.gnome.org/show_bug.cgi?id=708237
This commit is contained in:
Wim Taymans 2013-11-12 16:52:35 +01:00
parent adc02db975
commit b2bc84cdbf
2 changed files with 32 additions and 4 deletions

View file

@ -328,7 +328,7 @@ invalid:
} }
static void static void
inc_address (Addr * addr, guint8 count) inc_address (Addr * addr, guint count)
{ {
gint i; gint i;
guint carry; guint carry;
@ -342,7 +342,6 @@ inc_address (Addr * addr, guint8 count)
} }
/* tells us the number of addresses between min_addr and max_addr */ /* tells us the number of addresses between min_addr and max_addr */
static guint static guint
diff_address (Addr * max_addr, Addr * min_addr) diff_address (Addr * max_addr, Addr * min_addr)
{ {
@ -361,7 +360,6 @@ diff_address (Addr * max_addr, Addr * min_addr)
return result; return result;
} }
static AddrRange * static AddrRange *
split_range (GstRTSPAddressPool * pool, AddrRange * range, guint skip_addr, split_range (GstRTSPAddressPool * pool, AddrRange * range, guint skip_addr,
guint skip_port, gint n_ports) guint skip_port, gint n_ports)
@ -673,11 +671,13 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
ttl); ttl);
if (list != NULL) { if (list != NULL) {
AddrRange *range = list->data; AddrRange *range = list->data;
gint skip_port, skip_addr; guint skip_port, skip_addr;
skip_addr = diff_address (&input_addr, &range->min); skip_addr = diff_address (&input_addr, &range->min);
skip_port = port - range->min.port; skip_port = port - range->min.port;
GST_DEBUG_OBJECT (pool, "diff 0x%08x/%u", skip_addr, skip_port);
/* we found a range, remove from the list */ /* we found a range, remove from the list */
priv->addresses = g_list_delete_link (priv->addresses, list); priv->addresses = g_list_delete_link (priv->addresses, list);
/* now split and exit our loop */ /* now split and exit our loop */

View file

@ -236,6 +236,34 @@ GST_START_TEST (test_pool)
fail_unless (!strcmp (addr->address, "192.168.1.1")); fail_unless (!strcmp (addr->address, "192.168.1.1"));
gst_rtsp_address_free (addr); gst_rtsp_address_free (addr);
fail_unless (gst_rtsp_address_pool_add_range (pool,
GST_RTSP_ADDRESS_POOL_ANY_IPV4, GST_RTSP_ADDRESS_POOL_ANY_IPV4, 5000,
5001, 0));
res =
gst_rtsp_address_pool_reserve_address (pool, "192.168.0.1", 5000, 1, 0,
&addr);
fail_unless (res == GST_RTSP_ADDRESS_POOL_ERANGE);
res =
gst_rtsp_address_pool_reserve_address (pool, "0.0.0.0", 5000, 1, 0,
&addr);
fail_unless (res == GST_RTSP_ADDRESS_POOL_OK);
gst_rtsp_address_free (addr);
gst_rtsp_address_pool_clear (pool);
/* Error case 2. Using ANY as min address makes it possible to allocate the
* same address twice */
fail_unless (gst_rtsp_address_pool_add_range (pool,
GST_RTSP_ADDRESS_POOL_ANY_IPV4, "255.255.255.255", 5000, 5001, 0));
res =
gst_rtsp_address_pool_reserve_address (pool, "192.168.0.1", 5000, 1, 0,
&addr);
fail_unless (res == GST_RTSP_ADDRESS_POOL_OK);
res =
gst_rtsp_address_pool_reserve_address (pool, "192.168.0.1", 5000, 1, 0,
&addr2);
fail_unless (res == GST_RTSP_ADDRESS_POOL_ERESERVED);
gst_rtsp_address_free (addr);
gst_rtsp_address_pool_clear (pool);
g_object_unref (pool); g_object_unref (pool);
} }