[glib] Fix a FIXME in the WinXP inet_pton() implementation
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Fix a FIXME in the WinXP inet_pton() implementation
- Date: Mon, 29 Jun 2015 14:48:24 +0000 (UTC)
commit f9af40a1330a8226d72c96bff56cdb4ab895dac7
Author: Dan Winship <danw gnome org>
Date: Tue Jun 9 09:19:43 2015 -0400
Fix a FIXME in the WinXP inet_pton() implementation
https://bugzilla.gnome.org/show_bug.cgi?id=749912
gio/ginetaddress.c | 44 ++++++++++++++++----------------------------
1 files changed, 16 insertions(+), 28 deletions(-)
---
diff --git a/gio/ginetaddress.c b/gio/ginetaddress.c
index 9e069a4..c83f750 100644
--- a/gio/ginetaddress.c
+++ b/gio/ginetaddress.c
@@ -398,39 +398,27 @@ inet_pton (gint family,
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
gint len = sizeof (sa);
- /* We need to make sure to not pass a string of the form
- * "IPv4addr:port" or "[IPv6addr]:port" to WSAStringToAddress(),
- * since it would accept them (returning both the address and the
- * port), but we only want to accept standalone IP addresses. (In
- * the IPv6 case, WINE actually only checks for the ']', not the
- * '[', which is why we do the same here.)
- */
if (family != AF_INET && family != AF_INET6)
{
WSASetLastError (WSAEAFNOSUPPORT);
return -1;
}
- if (!strchr (addr_string, ':'))
- {
- if (WSAStringToAddress ((LPTSTR) addr_string, AF_INET, NULL, (LPSOCKADDR) &sa, &len) == 0)
- {
- /* XXX: Figure out when WSAStringToAddress() accepts a IPv4 address but the
- numbers-and-dots address is actually not complete. This code will be
- removed once XP/Server 2003 support is dropped... */
- *(IN_ADDR *) addr = sin->sin_addr;
-
- return 1;
- }
- }
- if (!strchr (addr_string, ']'))
- {
- if (WSAStringToAddress ((LPTSTR) addr_string, AF_INET6, NULL, (LPSOCKADDR) &sa, &len) == 0)
- {
- *(IN6_ADDR *) addr = sin6->sin6_addr;
- return 1;
- }
- }
- return 0;
+
+ /* WSAStringToAddress() will accept various not-an-IP-address
+ * strings like "127.0.0.1:80", "[1234::5678]:80", "127.1", etc.
+ */
+ if (!g_hostname_is_ip_address (addr_string))
+ return 0;
+
+ if (WSAStringToAddress ((LPTSTR) addr_string, family, NULL, (LPSOCKADDR) &sa, &len) != 0)
+ return 0;
+
+ if (family == AF_INET)
+ *(IN_ADDR *)addr = sin->sin_addr;
+ else
+ *(IN6_ADDR *)addr = sin6->sin6_addr;
+
+ return 1;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]