summaryrefslogtreecommitdiff
path: root/agent/interfaces.c
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-07-09 16:43:45 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-07-09 18:05:23 +0530
commit80dc194ff9bc6c780a27696dfd537130f5e7843e (patch)
tree805cdcbb16f07c4ce1d1f735f86ef10361c27721 /agent/interfaces.c
parent353f56206d998439f607dfc2d033e3debb24fa35 (diff)
downloadlibnice-80dc194ff9bc6c780a27696dfd537130f5e7843e.tar.gz
interfaces: Port to GetBestInterfaceEx for UWP compat
Still prefer ipv4 addresses for backwards-compat. GetBestInterface is not allowed when targeting UWP, so use GetBestInterfaceEx. Also add some debug logging to ensure that the function is actually running correctly.
Diffstat (limited to 'agent/interfaces.c')
-rw-r--r--agent/interfaces.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/agent/interfaces.c b/agent/interfaces.c
index 5c8d131..309ca65 100644
--- a/agent/interfaces.c
+++ b/agent/interfaces.c
@@ -600,8 +600,21 @@ GList * nice_interfaces_get_local_ips (gboolean include_loopback)
* Get the best interface for transport to 0.0.0.0.
* This interface should be first in list!
*/
- if (GetBestInterface (0, &pref) != NO_ERROR)
- pref = 0;
+ {
+ DWORD retcode;
+ struct sockaddr_in sa_any = {0};
+
+ sa_any.sin_family = AF_INET;
+ sa_any.sin_addr.s_addr = htonl (INADDR_ANY);
+
+ retcode = GetBestInterfaceEx ((SOCKADDR *) &sa_any, &pref);
+ if (retcode != NO_ERROR) {
+ gchar *msg = g_win32_error_message (retcode);
+ nice_debug ("Error fetching best interface: %s", msg);
+ g_free (msg);
+ pref = 0;
+ }
+ }
/* Loop over the adapters. */
for (a = addresses; a != NULL; a = a->Next) {