[gssdp] win32: Implement interface index lookup



commit a1faa61ee235c30f6aed2f249653520fc977f009
Author: Jens Georg <mail jensge org>
Date:   Sun Jul 4 17:14:19 2021 +0200

    win32: Implement interface index lookup

 libgssdp/gssdp-net-win32.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/libgssdp/gssdp-net-win32.c b/libgssdp/gssdp-net-win32.c
index 3341878..2eceffa 100644
--- a/libgssdp/gssdp-net-win32.c
+++ b/libgssdp/gssdp-net-win32.c
@@ -91,8 +91,28 @@ extract_address_and_prefix (PIP_ADAPTER_UNICAST_ADDRESS  adapter,
 int
 gssdp_net_query_ifindex (GSSDPNetworkDevice *device)
 {
-        /* TODO: if_nametoindex is supported on Vista or later */
-        return -1;
+        gunichar2 *wname =
+                g_utf8_to_utf16 (device->iface_name, -1, NULL, NULL, NULL);
+        CLSID clsid;
+        HRESULT hr = CLSIDFromString (wname, &clsid);
+        g_free (wname);
+
+        if (FAILED (hr)) {
+                return -1;
+        }
+
+        NET_LUID luid;
+        if (!NETIO_SUCCESS (ConvertInterfaceGuidToLuid ((const GUID *) &clsid,
+                                                        &luid))) {
+                return -1;
+        }
+
+        NET_IFINDEX ifindex;
+        if (!NETIO_SUCCESS (ConvertInterfaceLuidToIndex (&luid, &ifindex))) {
+                return -1;
+        }
+
+        return ifindex;
 }
 
 char *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]