diff options
author | Jens Georg <mail@jensge.org> | 2022-11-07 13:16:31 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2022-11-07 13:16:31 +0100 |
commit | 89716a6098121f0717574bbc35798a08c29a2702 (patch) | |
tree | f0fdedfe86a5f666d27e7e8de2b796e66430473d | |
parent | 1abd32f551604e0d9b44e7bdf12987cc76dd35b9 (diff) | |
download | gssdp-89716a6098121f0717574bbc35798a08c29a2702.tar.gz |
Client: Check scope ID only if IPv6
There are link-local addresses for IPv4 as well, but they do not have
scope ids. Avoid critical if running into such an address.
Fixes #22
-rw-r--r-- | libgssdp/gssdp-client.c | 3 | ||||
-rw-r--r-- | tests/test-regression.c | 38 |
2 files changed, 40 insertions, 1 deletions
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c index a81f81d..e68f86a 100644 --- a/libgssdp/gssdp-client.c +++ b/libgssdp/gssdp-client.c @@ -1390,7 +1390,8 @@ gssdp_client_can_reach (GSSDPClient *client, GInetSocketAddress *address) GSSDPClientPrivate *priv = gssdp_client_get_instance_private (client); GInetAddress *addr = g_inet_socket_address_get_address (address); - if (g_inet_address_get_is_link_local (addr)) { + if (g_inet_address_get_is_link_local (addr) && + g_inet_address_get_family (addr) == G_SOCKET_FAMILY_IPV6) { return g_inet_socket_address_get_scope_id (address) == priv->device.index; } diff --git a/tests/test-regression.c b/tests/test-regression.c index 1d9925d..c030e98 100644 --- a/tests/test-regression.c +++ b/tests/test-regression.c @@ -471,6 +471,43 @@ void test_ggo_7 () { * ============================================================================ */ +/* BEGIN Regression test + * https://gitlab.gnome.org/GNOME/gssdp/issues/22 + * ============================================================================ + * - Calling can_reach on a v4 link-local address causes a warning + */ + +void +test_ggo_22 () +{ + GError *error = NULL; + GInetAddress *addr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4); + GInetAddress *target_addr = + g_inet_address_new_from_string ("169.254.140.39"); + GSocketAddress *target = g_inet_socket_address_new (target_addr, 0); + + GSSDPClient *client = + gssdp_client_new_for_address (addr, + 0, + GSSDP_UDA_VERSION_1_0, + &error); + + g_assert_nonnull (client); + g_assert_no_error (error); + + // don't care for the result, just make sure that there is no warning + (void) gssdp_client_can_reach (client, G_INET_SOCKET_ADDRESS (target)); + + g_object_unref (client); + g_object_unref (target); + g_object_unref (target_addr); + g_object_unref (addr); +} + +/* END Regression test + * https://gitlab.gnome.org/GNOME/gssdp/issues/7 + * ============================================================================ + */ int main (int argc, char *argv[]) { @@ -486,6 +523,7 @@ int main (int argc, char *argv[]) g_test_add_func ("/bugs/ggo/1", test_ggo_1); } g_test_add_func ("/bugs/ggo/7", test_ggo_7); + g_test_add_func ("/bugs/ggo/22", test_ggo_22); g_test_run (); |