gnetworkaddress: preserve IPv6 scope ID in IP literals

If a GNetworkAddress is created with a hostname like "fe80::xxx%em1",
make sure that the scope_id corresponding to "em1" is present in the
GSocketAddresses it returns when used as a GSocketConnectable.

https://bugzilla.gnome.org/show_bug.cgi?id=684404
This commit is contained in:
Dan Winship
2012-12-12 16:12:09 +01:00
parent a44a3cc150
commit 8a77f7bb18
2 changed files with 100 additions and 26 deletions

View File

@@ -222,6 +222,43 @@ test_socket_address (void)
g_object_unref (saddr);
}
static void
test_scope_id (void)
{
GSocketConnectable *addr;
GSocketAddressEnumerator *addr_enum;
GSocketAddress *saddr;
GInetSocketAddress *isaddr;
GInetAddress *iaddr;
char *tostring;
GError *error = NULL;
addr = g_network_address_new ("fe80::42%1", 99);
addr_enum = g_socket_connectable_enumerate (addr);
saddr = g_socket_address_enumerator_next (addr_enum, NULL, &error);
g_assert_no_error (error);
g_assert (saddr != NULL);
g_assert (G_IS_INET_SOCKET_ADDRESS (saddr));
isaddr = G_INET_SOCKET_ADDRESS (saddr);
g_assert_cmpint (g_inet_socket_address_get_scope_id (isaddr), ==, 1);
g_assert_cmpint (g_inet_socket_address_get_port (isaddr), ==, 99);
iaddr = g_inet_socket_address_get_address (isaddr);
tostring = g_inet_address_to_string (iaddr);
g_assert_cmpstr (tostring, ==, "fe80::42");
g_free (tostring);
g_object_unref (saddr);
saddr = g_socket_address_enumerator_next (addr_enum, NULL, &error);
g_assert_no_error (error);
g_assert (saddr == NULL);
g_object_unref (addr_enum);
g_object_unref (addr);
}
static void
test_mask_parse (void)
{
@@ -355,6 +392,7 @@ main (int argc, char *argv[])
g_test_add_func ("/inet-address/bytes", test_bytes);
g_test_add_func ("/inet-address/property", test_property);
g_test_add_func ("/socket-address/basic", test_socket_address);
g_test_add_func ("/socket-address/scope-id", test_scope_id);
g_test_add_func ("/address-mask/parse", test_mask_parse);
g_test_add_func ("/address-mask/property", test_mask_property);
g_test_add_func ("/address-mask/equal", test_mask_equal);