diff --git a/configure.ac b/configure.ac index 30c57d2ba..e020dcfa7 100644 --- a/configure.ac +++ b/configure.ac @@ -1126,7 +1126,7 @@ if $glib_failed ; then AC_MSG_ERROR([Could not determine values for MSG_* constants]) fi -AC_CHECK_FUNCS(getprotobyname_r endservent if_nametoindex) +AC_CHECK_FUNCS(getprotobyname_r endservent if_nametoindex if_indextoname) AS_IF([test $glib_native_win32 = yes], [ # in the Windows SDK and in mingw-w64 has wrappers for diff --git a/gio/tests/inet-address.c b/gio/tests/inet-address.c index 0e82b0652..8052aecb9 100644 --- a/gio/tests/inet-address.c +++ b/gio/tests/inet-address.c @@ -20,7 +20,10 @@ * if advised of the possibility of such damage. */ +#include "config.h" + #include +#include static void test_parse (void) @@ -230,10 +233,26 @@ test_scope_id (void) GSocketAddress *saddr; GInetSocketAddress *isaddr; GInetAddress *iaddr; - char *tostring; + char *str, *tostring; GError *error = NULL; + int index; +#ifdef HAVE_IF_INDEXTONAME + char ifname[IF_NAMESIZE] = { 0 }; +#endif - addr = g_network_address_new ("fe80::42%1", 99); +#ifdef HAVE_IF_INDEXTONAME + for (index = 1; index < 255; index++) { + if (if_indextoname (1, ifname)) + break; + } + g_assert_cmpstr (ifname, !=, ""); + str = g_strdup_printf ("fe80::42%%%s", ifname); +#else + index = 1; + str = g_strdup ("fe80::42%1"); +#endif + + addr = g_network_address_new (str, 99); addr_enum = g_socket_connectable_enumerate (addr); saddr = g_socket_address_enumerator_next (addr_enum, NULL, &error); g_assert_no_error (error); @@ -242,7 +261,7 @@ test_scope_id (void) 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_scope_id (isaddr), ==, index); g_assert_cmpint (g_inet_socket_address_get_port (isaddr), ==, 99); iaddr = g_inet_socket_address_get_address (isaddr); @@ -257,6 +276,7 @@ test_scope_id (void) g_object_unref (addr_enum); g_object_unref (addr); + g_free (str); } static void