[glib] gio/tests/inet-address: fix to work on OS X
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gio/tests/inet-address: fix to work on OS X
- Date: Tue, 4 Jun 2013 12:28:37 +0000 (UTC)
commit 16b26231ca7d807a5bb52228eb4f2cae4427edde
Author: Dan Winship <danw gnome org>
Date: Sat May 25 11:09:43 2013 -0300
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
configure.ac | 2 +-
gio/tests/inet-address.c | 28 ++++++++++++++++++++++++----
2 files changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 30c57d2..e020dcf 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 0e82b06..8052aec 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]