summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-05-25 11:09:43 -0300
committerDan Winship <danw@gnome.org>2013-06-04 09:24:47 -0300
commit16b26231ca7d807a5bb52228eb4f2cae4427edde (patch)
tree4692013854cb71353f6f7791abf95d6d222d2084
parentc828aef014082c06f6a697ef4d0b92054d82b727 (diff)
downloadglib-16b26231ca7d807a5bb52228eb4f2cae4427edde.tar.gz
gio/tests/inet-address: fix to work on OS X
OS X's getaddrinfo() only supports IPv6 scope IDs that are interface names, not numbers. So use if_indextoname() to get the name of an interface and construct an address using that. https://bugzilla.gnome.org/show_bug.cgi?id=700123
-rw-r--r--configure.ac2
-rw-r--r--gio/tests/inet-address.c28
2 files changed, 25 insertions, 5 deletions
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], [
# <wspiapi.h> 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 <gio/gio.h>
+#include <gio/gnetworking.h>
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;
-
- addr = g_network_address_new ("fe80::42%1", 99);
+ int index;
+#ifdef HAVE_IF_INDEXTONAME
+ char ifname[IF_NAMESIZE] = { 0 };
+#endif
+
+#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