Commit cea728ee authored by Olivier Crête's avatar Olivier Crête

address: add nice_address_equal_no_port() to compare addresses ignoring ports

parent ee493a3e
......@@ -391,3 +391,23 @@ nice_address_ip_version (const NiceAddress *addr)
return 0;
}
}
NICEAPI_EXPORT gboolean
nice_address_equal_no_port (const NiceAddress *a, const NiceAddress *b)
{
if (a->s.addr.sa_family != b->s.addr.sa_family)
return FALSE;
switch (a->s.addr.sa_family)
{
case AF_INET:
return (a->s.ip4.sin_addr.s_addr == b->s.ip4.sin_addr.s_addr);
case AF_INET6:
return IN6_ARE_ADDR_EQUAL (&a->s.ip6.sin6_addr, &b->s.ip6.sin6_addr)
&& (a->s.ip6.sin6_scope_id == b->s.ip6.sin6_scope_id);
default:
g_return_val_if_reached (FALSE);
}
}
......@@ -235,12 +235,29 @@ nice_address_copy_to_sockaddr (const NiceAddress *addr, struct sockaddr *sin);
* @b: Second #NiceAddress to compare
*
* Compares two #NiceAddress structures to see if they contain the same address
* and the same port.
*
* Returns: %TRUE if @a and @b are the same address, %FALSE if they are different
*/
gboolean
nice_address_equal (const NiceAddress *a, const NiceAddress *b);
/**
* nice_address_equal_no_port:
* @a: First #NiceAddress to compare
* @b: Second #NiceAddress to compare
*
* Compares two #NiceAddress structures to see if they contain the same address,
* ignoring the port.
*
* Returns: %TRUE if @a and @b are the same address, %FALSE if they
* are different
*
* Since: UNRELEASED
*/
gboolean
nice_address_equal_no_port (const NiceAddress *a, const NiceAddress *b);
/**
* nice_address_to_string:
* @addr: The #NiceAddress to query
......
......@@ -112,6 +112,7 @@ nice_address_set_from_string
nice_address_set_from_sockaddr
nice_address_copy_to_sockaddr
nice_address_equal
nice_address_equal_no_port
nice_address_to_string
nice_address_is_private
nice_address_is_valid
......
nice_address_copy_to_sockaddr
nice_address_dup
nice_address_equal
nice_address_equal_no_port
nice_address_free
nice_address_get_port
nice_address_init
......
......@@ -5,6 +5,7 @@ EXPORTS
nice_address_copy_to_sockaddr
nice_address_dup
nice_address_equal
nice_address_equal_no_port
nice_address_free
nice_address_get_port
nice_address_init
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment