diff options
author | Jens Georg <mail@jensge.org> | 2021-07-04 17:14:19 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2021-07-04 17:14:19 +0200 |
commit | a1faa61ee235c30f6aed2f249653520fc977f009 (patch) | |
tree | 5486eb2929a2faf0bcc5c17734f8179336372711 | |
parent | e46ad6757e2396f45385a54e2ad9fbf1a36d2b60 (diff) | |
download | gssdp-a1faa61ee235c30f6aed2f249653520fc977f009.tar.gz |
win32: Implement interface index lookup
-rw-r--r-- | libgssdp/gssdp-net-win32.c | 24 |
1 files 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 * |