- memset (&sa, 0, sizeof (sa));
- len = sizeof (sa);
- if (WSAStringToAddress ((LPTSTR) string, AF_INET, NULL, (LPSOCKADDR) &sa, &len) == 0)
- return g_inet_address_new_from_bytes ((guint8 *)&sin->sin_addr, AF_INET);
- else if (WSAStringToAddress ((LPTSTR) string, AF_INET6, NULL, (LPSOCKADDR) &sa, &len) == 0)
- return g_inet_address_new_from_bytes ((guint8 *)&sin6->sin6_addr, AF_INET6);
+ /* 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 (!strchr (string, ':'))
+ {
+ len = sizeof (sa);
+ if (WSAStringToAddress ((LPTSTR) string, AF_INET, NULL, (LPSOCKADDR) &sa, &len) == 0)
+ return g_inet_address_new_from_bytes ((guint8 *)&sin->sin_addr, AF_INET);
+ }
+
+ if (!strchr (string, ']'))
+ {
+ len = sizeof (sa);
+ if (WSAStringToAddress ((LPTSTR) string, AF_INET6, NULL, (LPSOCKADDR) &sa, &len) == 0)
+ return g_inet_address_new_from_bytes ((guint8 *)&sin6->sin6_addr, AF_INET6);
+ }