mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-30 22:08:19 +01:00
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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user