Windows: Use Standard Networking Functions If Possible

Currently, the Windows code use Winsock2-specific APIs to try to emulate
calls such as inet_pton(), inet_ntop() and if_nametoindex(), which may not
do the job all the time.  On Vista and later, Winsock2 does provide a
proper implementation for these functions, so we can use them if they exist
on the system, by querying for them during g_networking_init().  Otherwise,
we continue to use the original code path for these, in the case of XP and
Server 2003.

This enables many of the network-address tests to pass on Windows as a
result, when the native Winsock2 implementations can be used.

https://bugzilla.gnome.org/show_bug.cgi?id=730352
This commit is contained in:
Chun-wei Fan
2015-03-05 16:13:03 +08:00
parent ec1edef3ab
commit 6fe28eef3c
5 changed files with 199 additions and 60 deletions

View File

@@ -64,6 +64,11 @@
#include "gcredentialsprivate.h"
#include "glibintl.h"
#ifdef G_OS_WIN32
/* For Windows XP runtime compatibility, but use the system's if_nametoindex() if available */
#include "gwin32networking.h"
#endif
/**
* SECTION:gsocket
* @short_description: Low-level socket object
@@ -1938,6 +1943,9 @@ if_nametoindex (const gchar *iface)
guint idx = 0;
DWORD res;
if (ws2funcs.pIfNameToIndex != NULL)
return ws2funcs.pIfNameToIndex (iface);
res = GetAdaptersAddresses (AF_UNSPEC, 0, NULL, NULL, &addresses_len);
if (res != NO_ERROR && res != ERROR_BUFFER_OVERFLOW)
{