mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
GSocket – Implement multicast interface selection on Windows
https://bugzilla.gnome.org/show_bug.cgi?id=697185
This commit is contained in:
parent
c069c51db5
commit
01156b122c
@ -316,7 +316,7 @@ win32_more_sources_for_vcproj = \
|
|||||||
|
|
||||||
if OS_WIN32
|
if OS_WIN32
|
||||||
appinfo_sources += gwin32appinfo.c gwin32appinfo.h
|
appinfo_sources += gwin32appinfo.c gwin32appinfo.h
|
||||||
platform_libadd += -lshlwapi -lws2_32 -ldnsapi
|
platform_libadd += -lshlwapi -lws2_32 -ldnsapi -liphlpapi
|
||||||
win32_sources = $(win32_actual_sources)
|
win32_sources = $(win32_actual_sources)
|
||||||
|
|
||||||
giowin32includedir=$(includedir)/gio-win32-2.0/gio
|
giowin32includedir=$(includedir)/gio-win32-2.0/gio
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <windns.h>
|
#include <windns.h>
|
||||||
#include <mswsock.h>
|
#include <mswsock.h>
|
||||||
@WSPIAPI_INCLUDE@
|
@WSPIAPI_INCLUDE@
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
|
||||||
#else /* !G_OS_WIN32 */
|
#else /* !G_OS_WIN32 */
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <windns.h>
|
#include <windns.h>
|
||||||
#include <mswsock.h>
|
#include <mswsock.h>
|
||||||
#include <wspiapi.h>
|
#include <wspiapi.h>
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
|
||||||
#else /* !G_OS_WIN32 */
|
#else /* !G_OS_WIN32 */
|
||||||
|
|
||||||
|
@ -1934,6 +1934,60 @@ g_socket_bind (GSocket *socket,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(HAVE_IF_NAMETOINDEX) && defined(G_OS_WIN32)
|
||||||
|
static guint
|
||||||
|
if_nametoindex (const gchar *iface)
|
||||||
|
{
|
||||||
|
PIP_ADAPTER_ADDRESSES addresses = NULL, p;
|
||||||
|
gulong addresses_len = 0;
|
||||||
|
guint idx = 0;
|
||||||
|
DWORD res;
|
||||||
|
|
||||||
|
res = GetAdaptersAddresses (AF_UNSPEC, 0, NULL, NULL, &addresses_len);
|
||||||
|
if (res != NO_ERROR && res != ERROR_BUFFER_OVERFLOW)
|
||||||
|
{
|
||||||
|
if (res == ERROR_NO_DATA)
|
||||||
|
errno = ENXIO;
|
||||||
|
else
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
addresses = g_malloc (addresses_len);
|
||||||
|
res = GetAdaptersAddresses (AF_UNSPEC, 0, NULL, addresses, &addresses_len);
|
||||||
|
|
||||||
|
if (res != NO_ERROR)
|
||||||
|
{
|
||||||
|
g_free (addresses);
|
||||||
|
if (res == ERROR_NO_DATA)
|
||||||
|
errno = ENXIO;
|
||||||
|
else
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = addresses;
|
||||||
|
while (p)
|
||||||
|
{
|
||||||
|
if (strcmp (p->AdapterName, iface) == 0)
|
||||||
|
{
|
||||||
|
idx = p->IfIndex;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p = p->Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p == NULL)
|
||||||
|
errno = ENXIO;
|
||||||
|
|
||||||
|
g_free (addresses);
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HAVE_IF_NAMETOINDEX 1
|
||||||
|
#endif
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
g_socket_multicast_group_operation (GSocket *socket,
|
g_socket_multicast_group_operation (GSocket *socket,
|
||||||
GInetAddress *group,
|
GInetAddress *group,
|
||||||
@ -1969,6 +2023,11 @@ g_socket_multicast_group_operation (GSocket *socket,
|
|||||||
mc_req.imr_ifindex = if_nametoindex (iface);
|
mc_req.imr_ifindex = if_nametoindex (iface);
|
||||||
else
|
else
|
||||||
mc_req.imr_ifindex = 0; /* Pick any. */
|
mc_req.imr_ifindex = 0; /* Pick any. */
|
||||||
|
#elif defined(G_OS_WIN32)
|
||||||
|
if (iface)
|
||||||
|
mc_req.imr_interface.s_addr = g_htonl (if_nametoindex (iface));
|
||||||
|
else
|
||||||
|
mc_req.imr_interface.s_addr = g_htonl (INADDR_ANY);
|
||||||
#else
|
#else
|
||||||
mc_req.imr_interface.s_addr = g_htonl (INADDR_ANY);
|
mc_req.imr_interface.s_addr = g_htonl (INADDR_ANY);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user