[glib/w32-testsuite-fixes-socket: 3/3] socket test: Use loopback for connecting, not 0.0.0.0
- From: LRN <ruslanizhb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/w32-testsuite-fixes-socket: 3/3] socket test: Use loopback for connecting, not 0.0.0.0
- Date: Wed, 13 Feb 2019 18:27:07 +0000 (UTC)
commit c00724d5c92b3fe8a628dcdab3770cf0330d2b9f
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date: Mon Feb 11 23:45:53 2019 +0000
socket test: Use loopback for connecting, not 0.0.0.0
getsockname() returns the address that the socket was bound to.
If it was bound to INADDR_ANY, getsockname() will stubbornly return INADDR_ANY
(and someport - that one is valid).
Subsequent connection attempts to INADDR_ANY:someport will fail with winsock.
Actually, it doesn't make even sense to connect to INADDR_ANY at all
(where is the socket connecting to? To a random interface of the host?),
so this is just a straight-up change, without platform-specific ifdefing.
Use loopback instead of INADDR_ANY. To ensure that binding and creation
of INADDR_ANY is still tested, use two addresses: bind to INADDR_ANY,
but connect to loopback, with the port number that we got from the bound
address.
gio/tests/socket.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index a3f3c43cb..eeebddd62 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -1602,7 +1602,7 @@ test_get_available (gconstpointer user_data)
GError *err = NULL;
GSocket *listener, *server, *client;
GInetAddress *addr;
- GSocketAddress *saddr;
+ GSocketAddress *saddr, *boundaddr;
gchar data[] = "0123456789abcdef";
gchar buf[34];
gssize nread;
@@ -1635,9 +1635,14 @@ test_get_available (gconstpointer user_data)
g_object_unref (saddr);
g_object_unref (addr);
- saddr = g_socket_get_local_address (listener, &err);
+ boundaddr = g_socket_get_local_address (listener, &err);
g_assert_no_error (err);
+ addr = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4);
+ saddr = g_inet_socket_address_new (addr, g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS
(boundaddr)));
+ g_object_unref (addr);
+ g_object_unref (boundaddr);
+
if (socket_type == G_SOCKET_TYPE_STREAM)
{
g_socket_listen (listener, &err);
@@ -1799,7 +1804,7 @@ test_read_write (gconstpointer user_data)
GError *err = NULL;
GSocket *listener, *server, *client;
GInetAddress *addr;
- GSocketAddress *saddr;
+ GSocketAddress *saddr, *boundaddr;
TestReadWriteData data;
guint8 data_write[1024], data_read[1024];
GSocketConnection *server_stream, *client_stream;
@@ -1828,11 +1833,17 @@ test_read_write (gconstpointer user_data)
g_object_unref (saddr);
g_object_unref (addr);
- saddr = g_socket_get_local_address (listener, &err);
+ boundaddr = g_socket_get_local_address (listener, &err);
g_assert_no_error (err);
g_socket_listen (listener, &err);
g_assert_no_error (err);
+
+ addr = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4);
+ saddr = g_inet_socket_address_new (addr, g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS
(boundaddr)));
+ g_object_unref (addr);
+ g_object_unref (boundaddr);
+
g_socket_connect (client, saddr, NULL, &err);
g_assert_no_error (err);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]