Index: /trunk/include/VBox/VBoxNetCfg-win.h
===================================================================
--- /trunk/include/VBox/VBoxNetCfg-win.h	(revision 58873)
+++ /trunk/include/VBox/VBoxNetCfg-win.h	(revision 58874)
@@ -35,5 +35,5 @@
  * still being 'committed' by the network setup engine.
  */
-//#define VBOXNETCFG_DELAYEDRENAME
+#define VBOXNETCFG_DELAYEDRENAME
 
 #include <winsock2.h>
Index: /trunk/src/VBox/Main/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Main/Makefile.kmk	(revision 58873)
+++ /trunk/src/VBox/Main/Makefile.kmk	(revision 58874)
@@ -302,5 +302,5 @@
 endif
 VBoxSVC_DEFS.win += VBOX_COM_OUTOFPROC_MODULE
-VBoxSVC_DEFS.win += _WIN32_WINNT=0x0510
+VBoxSVC_DEFS.win += _WIN32_WINNT=0x0600
 # Try to load and use libhal at runtime for probing removable media
 # VBoxSVC_DEFS.linux += VBOX_USE_LIBHAL
Index: /trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/win/NetIf-win.cpp	(revision 58873)
+++ /trunk/src/VBox/Main/src-server/win/NetIf-win.cpp	(revision 58874)
@@ -1473,24 +1473,25 @@
 }
 
-#ifndef NETIF_WITHOUT_NETCFG
-int NetIfList(std::list<ComObjPtr<HostNetworkInterface> > &list)
-{
-#ifndef VBOX_WITH_NETFLT
-    return VERR_NOT_IMPLEMENTED;
-#else /* #  if defined VBOX_WITH_NETFLT */
-    INetCfg              *pNc = NULL;
-    INetCfgComponent     *pMpNcc;
-    INetCfgComponent     *pTcpIpNcc;
+
+#define netIfLog LogRel
+
+struct BoundAdapter
+{
+    LPWSTR                pName;
+    LPWSTR                pHwId;
+    RTUUID                guid;
+    PIP_ADAPTER_ADDRESSES pAdapter;
+};
+
+static HRESULT netIfGetBoundAdapters(std::list<BoundAdapter> &boundAdapters)
+{
+    INetCfg              *pNetCfg = NULL;
+    INetCfgComponent     *pFilter;
     LPWSTR               lpszApp;
     HRESULT              hr;
-    IEnumNetCfgBindingPath      *pEnumBp;
-    INetCfgBindingPath          *pBp;
-    IEnumNetCfgBindingInterface *pEnumBi;
-    INetCfgBindingInterface *pBi;
-    int                  iDefault = getDefaultInterfaceIndex();
-
-    Log(("NetIfList: building the list of interfaces\n"));
+
+    netIfLog(("netIfGetBoundAdapters: building the list of interfaces\n"));
     /* we are using the INetCfg API for getting the list of miniports */
-    hr = VBoxNetCfgWinQueryINetCfg(&pNc, FALSE,
+    hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, FALSE,
                        VBOX_APP_NAME,
                        10000,
@@ -1499,230 +1500,163 @@
     if (hr != S_OK)
     {
-        if (pNc)
-            pNc->Release();
-        pNc = NULL;
-        LogRel(("NetIfList: failed to acquire INetCfg interface (0x%x), trying CoCreateInstance...\n", hr));
-        hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (PVOID*)&pNc);
-        if (SUCCEEDED(hr))
-        {
-            hr = pNc->Initialize(NULL);
-            if (FAILED(hr))
-            {
-                LogRel(("NetIfList: INetCfg::Initialize failed with 0x%x\n", hr));
-                if (pNc)
-                    pNc->Release();
-                pNc = NULL;
-            }
-        }
+        netIfLog(("netIfGetBoundAdapters: failed to query INetCfg (0x%x)\n", hr));
+        return hr;
+    }
+
+    if ((hr = pNetCfg->FindComponent(L"oracle_VBoxNetLwf", &pFilter)) != S_OK)
+        netIfLog(("netIfGetBoundAdapters: could not find 'oracle_VBoxNetLwf' component (0x%x)\n", hr));
+    else
+    {
+        INetCfgComponentBindings *pFilterBindings;
+        if ((pFilter->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pFilterBindings)) != S_OK)
+            netIfLog(("netIfGetBoundAdapters: failed to query INetCfgComponentBindings (0x%x)\n", hr));
         else
-            LogRel(("NetIfList: CoCreateInstance failed with 0x%x\n", hr));
-    }
-
-    if (hr == S_OK)
-    {
-# ifdef VBOX_NETFLT_ONDEMAND_BIND
-        /* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
-        hr = pNc->FindComponent(L"MS_TCPIP", &pTcpIpNcc);
-# else
-        /* for the filter-based approach we get all miniports our filter (oracle_VBoxNetLwf)is bound to */
-        hr = pNc->FindComponent(L"oracle_VBoxNetLwf", &pTcpIpNcc);
-        if (hr != S_OK)
-        {
-            LogRel(("NetIfList: could not find VBoxNetLwf component (error 0x%x), trying VBoxNetFlt instead\n", hr));
-            /* fall back to NDIS5 miniport lookup (sun_VBoxNetFlt) */
-            hr = pNc->FindComponent(L"sun_VBoxNetFlt", &pTcpIpNcc);
-        }
-#  ifndef VBOX_WITH_HARDENING
-        if (hr != S_OK)
-        {
-            /* TODO: try to install the netflt from here */
-        }
-#  endif
-
-# endif
-
-        if (hr == S_OK)
-        {
-            INetCfgComponentBindings *pBindings;
-            hr = pTcpIpNcc->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pBindings);
-            Assert(hr == S_OK);
-            if (hr == S_OK)
-            {
-                hr = pBindings->EnumBindingPaths(EBP_BELOW, &pEnumBp);
-                Assert(hr == S_OK);
-                if (hr == S_OK)
-                {
-                    hr = pEnumBp->Reset();
-                    Assert(hr == S_OK);
-                    if (hr == S_OK)
-                    {
-                        while ((hr = pEnumBp->Next(1, &pBp, NULL)) == S_OK)
+        {
+            IEnumNetCfgBindingPath *pEnumBp;
+            INetCfgBindingPath     *pBp;
+            if ((pFilterBindings->EnumBindingPaths(EBP_BELOW, &pEnumBp)) != S_OK)
+                netIfLog(("netIfGetBoundAdapters: failed to enumerate binding paths (0x%x)\n", hr));
+            else
+            {
+                pEnumBp->Reset();
+                while ((hr = pEnumBp->Next(1, &pBp, NULL)) == S_OK)
+                {
+                    IEnumNetCfgBindingInterface *pEnumBi;
+                    INetCfgBindingInterface     *pBi;
+                    if (pBp->IsEnabled() != S_OK)
+                    {
+                        /* @todo some id of disabled path could be useful. */
+                        netIfLog(("netIfGetBoundAdapters: INetCfgBindingPath is disabled (0x%x)\n", hr));
+                        pBp->Release();
+                        continue;
+                    }
+                    if ((pBp->EnumBindingInterfaces(&pEnumBi)) != S_OK)
+                        netIfLog(("netIfGetBoundAdapters: failed to enumerate binding interfaces (0x%x)\n", hr));
+                    else
+                    {
+                        hr = pEnumBi->Reset();
+                        while ((hr = pEnumBi->Next(1, &pBi, NULL)) == S_OK)
                         {
-                            Log(("NetIfList: fetched INetCfgBindingPath interface\n"));
-                            /* S_OK == enabled, S_FALSE == disabled */
-                            if (pBp->IsEnabled() == S_OK)
+                            INetCfgComponent *pAdapter;
+                            if ((hr = pBi->GetLowerComponent(&pAdapter)) != S_OK)
+                                netIfLog(("netIfGetBoundAdapters: failed to get lower component (0x%x)\n", hr));
+                            else
                             {
-                                hr = pBp->EnumBindingInterfaces(&pEnumBi);
-                                Assert(hr == S_OK);
-                                if (hr == S_OK)
+                                LPWSTR pwszName = NULL;
+                                if ((hr = pAdapter->GetDisplayName(&pwszName)) != S_OK)
+                                    netIfLog(("netIfGetBoundAdapters: failed to get display name (0x%x)\n", hr));
+                                else
                                 {
-                                    hr = pEnumBi->Reset();
-                                    Assert(hr == S_OK);
-                                    if (hr == S_OK)
+                                    ULONG uStatus;
+                                    DWORD dwChars;
+                                    if ((hr = pAdapter->GetDeviceStatus(&uStatus)) != S_OK)
+                                        netIfLog(("netIfGetBoundAdapters: %ls: failed to get device status (0x%x)\n",
+                                                  pwszName, hr));
+                                    else if ((hr = pAdapter->GetCharacteristics(&dwChars)) != S_OK)
+                                        netIfLog(("netIfGetBoundAdapters: %ls: failed to get device characteristics (0x%x)\n",
+                                                  pwszName, hr));
+                                    else if (uStatus != 0)
+                                        netIfLog(("netIfGetBoundAdapters: %ls: wrong status 0x%x\n",
+                                                  pwszName, uStatus));
+                                    else if ((dwChars & NCF_HIDDEN) || !(dwChars & (NCF_VIRTUAL | NCF_PHYSICAL)))
+                                        netIfLog(("netIfGetBoundAdapters: %ls: wrong characteristics 0x%x\n",
+                                                  pwszName, dwChars));
+                                    else
                                     {
-                                        while ((hr = pEnumBi->Next(1, &pBi, NULL)) == S_OK)
+                                        GUID guid;
+                                        LPWSTR pwszHwId = NULL;
+                                        if ((hr = pAdapter->GetId(&pwszHwId)) != S_OK)
+                                            netIfLog(("netIfGetBoundAdapters: %ls: failed to get hardware id (0x%x)\n",
+                                                      pwszName, hr));
+                                        else if ((hr = pAdapter->GetInstanceGuid(&guid)) != S_OK)
+                                            netIfLog(("netIfGetBoundAdapters: %ls: failed to get instance GUID (0x%x)\n",
+                                                      pwszName, hr));
+                                        else
                                         {
-                                            Log(("NetIfList: fetched INetCfgBindingInterface interface\n"));
-                                            hr = pBi->GetLowerComponent(&pMpNcc);
-                                            Assert(hr == S_OK);
-                                            if (hr == S_OK)
-                                            {
-                                                LPWSTR pwszName;
-                                                ULONG uComponentStatus;
-                                                hr = pMpNcc->GetDisplayName(&pwszName);
-                                                if (hr == S_OK)
-                                                    Log(("NetIfList: got %ls\n", pwszName));
-                                                else
-                                                    LogRel(("NetIfList: failed to get device display name (0x%x)\n", hr));
-                                                hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
-                                                if (hr == S_OK)
-                                                {
-                                                    if (uComponentStatus == 0)
-                                                    {
-                                                        LPWSTR pId;
-                                                        hr = pMpNcc->GetId(&pId);
-                                                        Assert(hr == S_OK);
-                                                        if (hr == S_OK)
-                                                        {
-                                                            Log(("NetIfList: fetched network adapter id: %.80ls\n", pId));
-                                                            /*
-                                                             * Host-only interfaces are ignored here and included into the list
-                                                             * later in netIfListHostAdapters()
-                                                             */
-                                                            if (_wcsnicmp(pId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2))
-                                                            {
-                                                                vboxNetWinAddComponent(&list, pMpNcc, HostNetworkInterfaceType_Bridged,
-                                                                                       iDefault);
-                                                            }
-                                                            CoTaskMemFree(pId);
-                                                        }
-                                                        else
-                                                            LogRel(("NetIfList: failed to get device id (0x%x)\n", hr));
-                                                    }
-                                                    else
-                                                        LogRel(("NetIfList: wrong device status (0x%x)\n", uComponentStatus));
-                                                }
-                                                else
-                                                    LogRel(("NetIfList: failed to get device status (0x%x)\n", hr));
-                                                pMpNcc->Release();
-                                            }
-                                            else
-                                                LogRel(("NetIfList: failed to get lower component (0x%x)\n", hr));
-                                            pBi->Release();
+                                            struct BoundAdapter adapter;
+                                            adapter.pName    = pwszName;
+                                            adapter.pHwId    = pwszHwId;
+                                            adapter.guid     = *(Guid(guid).raw());
+                                            adapter.pAdapter = NULL;
+                                            netIfLog(("netIfGetBoundAdapters: guid=%RTuuid, name=%ls, hwid=%ls, status=%x, chars=%x\n",
+                                                      &adapter.guid, pwszName, pwszHwId, uStatus, dwChars));
+                                            boundAdapters.push_back(adapter);
+                                            pwszName = pwszHwId = NULL; /* do not free, will be done later */
                                         }
-                                        Assert(hr == S_OK || hr == S_FALSE);
+                                        if (pwszHwId)
+                                            CoTaskMemFree(pwszHwId);
                                     }
-                                    else
-                                        LogRel(("NetIfList: IEnumNetCfgBindingInterface::Reset failed (0x%x)\n", hr));
-                                    pEnumBi->Release();
+                                    if (pwszName)
+                                        CoTaskMemFree(pwszName);
                                 }
-                                else
-                                    LogRel(("NetIfList: failed to enumerate binding interfaces (0x%x)\n", hr));
+
+                                pAdapter->Release();
                             }
-                            else
-                                LogRel(("NetIfList: INetCfgBindingPath is disabled\n"));
-                            pBp->Release();
+                            pBi->Release();
                         }
-                        Assert(hr == S_OK || hr == S_FALSE);
-                    }
+                        pEnumBi->Release();
+                    }
+                    pBp->Release();
+                }
+                pEnumBp->Release();
+            }
+            pFilterBindings->Release();
+        }
+        pFilter->Release();
+    }
+    VBoxNetCfgWinReleaseINetCfg(pNetCfg, FALSE);
+
+    return S_OK;
+}
+
+#if 0
+static HRESULT netIfGetBoundAdaptersFallback(std::list<BoundAdapter> &boundAdapters)
+{
+    return CO_E_NOT_SUPPORTED;
+}
+#endif
+
+static void netIfFillInfoWithAddresses(PNETIFINFO pInfo, PIP_ADAPTER_ADDRESSES pAdapter)
+{
+    PIP_ADAPTER_UNICAST_ADDRESS pAddr;
+
+    if (sizeof(pInfo->MACAddress) != pAdapter->PhysicalAddressLength)
+        netIfLog(("netIfFillInfoWithAddresses: Unexpected physical address length: %u\n", pAdapter->PhysicalAddressLength));
+    else
+        memcpy(pInfo->MACAddress.au8, pAdapter->PhysicalAddress, sizeof(pInfo->MACAddress));
+
+    bool fIPFound = false;
+    bool fIPv6Found = false;
+    for (pAddr = pAdapter->FirstUnicastAddress; pAddr; pAddr = pAddr->Next)
+    {
+        switch (pAddr->Address.lpSockaddr->sa_family)
+        {
+            case AF_INET:
+                if (!fIPFound)
+                {
+                    fIPFound = true;
+                    memcpy(&pInfo->IPAddress,
+                           &((struct sockaddr_in *)pAddr->Address.lpSockaddr)->sin_addr.s_addr,
+                           sizeof(pInfo->IPAddress));
+                    if (pAddr->OnLinkPrefixLength > 32)
+                        netIfLog(("netIfFillInfoWithAddresses: Invalid IPv4 prefix length of %d\n", pAddr->OnLinkPrefixLength));
                     else
-                        LogRel(("NetIfList: IEnumNetCfgBindingPath::Reset failed (0x%x)\n", hr));
-                    pEnumBp->Release();
-                }
-                else
-                    LogRel(("NetIfList: EnumBindingPaths failed (0x%x)\n", hr));
-                pBindings->Release();
-            }
-            else
-                LogRel(("NetIfList: failed to acquire INetCfgComponentBindings interface\n"));
-            pTcpIpNcc->Release();
-        }
-        else
-        {
-            LogRel(("failed to get the oracle_VBoxNetLwf(sun_VBoxNetFlt) component, error (0x%x)\n", hr));
-        }
-
-        /* Add host-only adapters to the list */
-        netIfListHostAdapters(pNc, list);
-
-        VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
-    }
-
-    return VINF_SUCCESS;
-#endif /* #  if defined VBOX_WITH_NETFLT */
-}
-
-#else /* !NETIF_WITHOUT_NETCFG */
-
-static void getTypeAndName(PIP_ADAPTER_ADDRESSES pAdapter, HostNetworkInterfaceType *enmType, PWCHAR pwszName, int cbName)
-{
-    /* In case we fail to get the right values we initialize them with best-effort defaults. */
-    *enmType = wcsncmp(pAdapter->Description, L"VirtualBox", 10) == 0
-                       ? HostNetworkInterfaceType_HostOnly
-                       : HostNetworkInterfaceType_Bridged;
-    wcscpy_s(pwszName, cbName / sizeof(*pwszName), pAdapter->Description);
-
-    char szKeyName[256];
-    sprintf_s(szKeyName, sizeof(szKeyName),
-              "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
-              pAdapter->AdapterName);
-    HKEY hkeyConnection;
-    LONG status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hkeyConnection);
-    if (status != ERROR_SUCCESS)
-    {
-        LogRel(("NetIf: Failed to find connection key in registry for %ls at %s\n",
-                pAdapter->Description, szKeyName));
-    }
-    else
-    {
-        WCHAR wszId[256];
-        DWORD dwLen = sizeof(wszId);
-        status = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, NULL, (LPBYTE)wszId, &dwLen);
-        if (status != ERROR_SUCCESS)
-        {
-            LogRel(("NetIf: Failed to get PnPInstanceID from registry for %ls\n", pAdapter->Description));
-        }
-        else
-        {
-            HDEVINFO hDevInfo = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_NET, NULL);
-            if (hDevInfo != INVALID_HANDLE_VALUE)
-            {
-                SP_DEVINFO_DATA DevInfoData;
-                
-                DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
-                if (SetupDiOpenDeviceInfo(hDevInfo, wszId, NULL, 0, &DevInfoData))
-                {
-                    if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, &DevInfoData,
-                                                          SPDRP_HARDWAREID, NULL,
-                                                          (PBYTE)wszId, sizeof(wszId), NULL))
-                    {
-                        /*
-                         * We do not care for multiple strings that may have been
-                         * returned since our host-only adapter has a single id.
-                         */
-                        if (_wcsnicmp(wszId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2))
-                            *enmType = HostNetworkInterfaceType_Bridged;
-                        else
-                            *enmType = HostNetworkInterfaceType_HostOnly;
-                    }
-                    SetupDiGetDeviceRegistryPropertyW(hDevInfo, &DevInfoData,
-                                                      SPDRP_FRIENDLYNAME, NULL,
-                                                      (PBYTE)pwszName, cbName, NULL);
-                }
-                SetupDiDestroyDeviceInfoList(hDevInfo);
-            }
-            LogRel(("PnP ID: %ls\n", wszId));
-        }
-        RegCloseKey(hkeyConnection);
+                        ASMBitSetRange(&pInfo->IPNetMask, 0, pAddr->OnLinkPrefixLength);
+                }
+                break;
+            case AF_INET6:
+                if (!fIPv6Found)
+                {
+                    fIPv6Found = true;
+                    memcpy(&pInfo->IPv6Address,
+                           ((struct sockaddr_in6 *)pAddr->Address.lpSockaddr)->sin6_addr.s6_addr,
+                           sizeof(pInfo->IPv6Address));
+                    if (pAddr->OnLinkPrefixLength > 128)
+                        netIfLog(("netIfFillInfoWithAddresses: Invalid IPv6 prefix length of %d\n", pAddr->OnLinkPrefixLength));
+                    else
+                        ASMBitSetRange(&pInfo->IPv6NetMask, 0, pAddr->OnLinkPrefixLength);
+                }
+                break;
+        }
     }
 }
@@ -1730,164 +1664,111 @@
 int NetIfList(std::list<ComObjPtr<HostNetworkInterface> > &list)
 {
-    DWORD dwRc;
-    int rc = VINF_SUCCESS;
+    HRESULT hr = S_OK;
     int iDefault = getDefaultInterfaceIndex();
-    /*
-     * Most of the hosts probably have less than 10 adapters,
-     * so we'll mostly succeed from the first attempt.
-     */
-    ULONG uBufLen = sizeof(IP_ADAPTER_ADDRESSES) * 10;
+    /* MSDN recommends to pre-allocate a 15KB buffer. */
+    ULONG uBufLen = 15 * 1024;
     PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)RTMemAlloc(uBufLen);
     if (!pAddresses)
-        return VERR_NO_MEMORY;
-    dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
-    if (dwRc == ERROR_BUFFER_OVERFLOW)
-    {
-        /* Impressive! More than 10 adapters! Get more memory and try again. */
-        RTMemFree(pAddresses);
+        return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
+    DWORD dwRc = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses, &uBufLen);
+    for (int tries = 0; tries < 3 && dwRc == ERROR_BUFFER_OVERFLOW; ++tries)
+    {
+        /* Get more memory and try again. */
+        free(pAddresses);
         pAddresses = (PIP_ADAPTER_ADDRESSES)RTMemAlloc(uBufLen);
         if (!pAddresses)
-            return VERR_NO_MEMORY;
-        dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
-    }
-    if (dwRc == NO_ERROR)
-    {
-        PIP_ADAPTER_ADDRESSES pAdapter;
-        for (pAdapter = pAddresses; pAdapter; pAdapter = pAdapter->Next)
-        {
-            Log(("Enumerating %s\n", pAdapter->AdapterName));
-            /* Vista+ systems introduced separate type for wireless adapters */
-            if (pAdapter->IfType != IF_TYPE_ETHERNET_CSMACD && pAdapter->IfType != IF_TYPE_IEEE80211)
-            {
-                LogRel(("Skipped non-Ethernet '%ls'\n", pAdapter->FriendlyName));
-                continue;
-            }
-
-            NETIFINFO Info;
-            RT_ZERO(Info);
-
-            if (pAdapter->AdapterName[0] == '{')
-            {
-                bool fIPv4Found, fIPv6Found;
-                PIP_ADAPTER_UNICAST_ADDRESS pAddr;
-                fIPv4Found = fIPv6Found = false;
-                for (pAddr = pAdapter->FirstUnicastAddress;
-                     pAddr && !(fIPv4Found && fIPv6Found);
-                     pAddr = pAddr->Next)
-                {
-                    switch (pAddr->Address.lpSockaddr->sa_family)
-                    {
-                        case AF_INET:
-                            if (!fIPv4Found)
-                            {
-                                fIPv4Found = true;
-                                memcpy(&Info.IPAddress,
-                                       &((struct sockaddr_in *)pAddr->Address.lpSockaddr)->sin_addr.s_addr,
-                                       sizeof(Info.IPAddress));
-                            }
+            return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
+        dwRc = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses, &uBufLen);
+    }
+    if (dwRc != NO_ERROR)
+    {
+        netIfLog(("NetIfList: GetAdaptersAddresses failed (0x%x)\n", dwRc));
+        hr = HRESULT_FROM_WIN32(dwRc);
+    }
+    else
+    {
+        std::list<BoundAdapter> boundAdapters;
+        HRESULT hr = netIfGetBoundAdapters(boundAdapters);
+#if 0
+        if (hr != S_OK)
+            hr = netIfGetBoundAdaptersFallback(boundAdapters);
+#endif
+        if (hr != S_OK)
+            netIfLog(("NetIfList: netIfGetBoundAdapters failed (0x%x)\n", hr));
+        else
+        {
+            PIP_ADAPTER_ADDRESSES pAdapter;
+
+            for (pAdapter = pAddresses; pAdapter; pAdapter = pAdapter->Next)
+            {
+                char *pszUuid = RTStrDup(pAdapter->AdapterName);
+                if (!pszUuid)
+                {
+                    netIfLog(("NetIfList: out of memory\n"));
+                    break;
+                }
+                size_t len = strlen(pszUuid) - 1;
+                if (pszUuid[0] != '{' || pszUuid[len] != '}')
+                    netIfLog(("NetIfList: ignoring invalid GUID %s\n", pAdapter->AdapterName));
+                else
+                {
+                    std::list<BoundAdapter>::iterator it;
+                    pszUuid[len] = 0;
+                    for (it = boundAdapters.begin(); it != boundAdapters.end(); ++it)
+                    {
+                        if (!RTUuidCompareStr(Guid((*it).guid).raw(), pszUuid + 1))
+                        {
+                            (*it).pAdapter = pAdapter;
                             break;
-                        case AF_INET6:
-                            if (!fIPv6Found)
-                            {
-                                fIPv6Found = true;
-                                memcpy(&Info.IPv6Address,
-                                       ((struct sockaddr_in6 *)pAddr->Address.lpSockaddr)->sin6_addr.s6_addr,
-                                       sizeof(Info.IPv6Address));
-                            }
-                            break;
-                    }
-                }
-                PIP_ADAPTER_PREFIX pPrefix;
-                fIPv4Found = fIPv6Found = false;
-                for (pPrefix = pAdapter->FirstPrefix;
-                     pPrefix && !(fIPv4Found && fIPv6Found);
-                     pPrefix = pPrefix->Next)
-                {
-                    switch (pPrefix->Address.lpSockaddr->sa_family)
-                    {
-                        case AF_INET:
-                            if (!fIPv4Found)
-                            {
-                                if (pPrefix->PrefixLength <= sizeof(Info.IPNetMask) * 8)
-                                {
-                                    fIPv4Found = true;
-                                    ASMBitSetRange(&Info.IPNetMask, 0, pPrefix->PrefixLength);
-                                }
-                                else
-                                    LogRel(("NetIfList: Unexpected IPv4 prefix length of %d\n",
-                                            pPrefix->PrefixLength));
-                            }
-                            break;
-                        case AF_INET6:
-                            if (!fIPv6Found)
-                            {
-                                if (pPrefix->PrefixLength <= sizeof(Info.IPv6NetMask) * 8)
-                                {
-                                    fIPv6Found = true;
-                                    ASMBitSetRange(&Info.IPv6NetMask, 0, pPrefix->PrefixLength);
-                                }
-                                else
-                                    LogRel(("NetIfList: Unexpected IPv6 prefix length of %d\n",
-                                            pPrefix->PrefixLength));
-                            }
-                            break;
-                    }
-                }
-                if (sizeof(Info.MACAddress) != pAdapter->PhysicalAddressLength)
-                    LogRel(("NetIfList: Unexpected physical address length: %u\n",
-                            pAdapter->PhysicalAddressLength));
+                        }
+                    }
+                }
+                RTStrFree(pszUuid);
+            }
+            std::list<BoundAdapter>::iterator it;
+            for (it = boundAdapters.begin(); it != boundAdapters.end(); ++it)
+            {
+                NETIFINFO info;
+                memset(&info, 0, sizeof(info));
+                info.Uuid = (*it).guid;
+                info.enmMediumType = NETIF_T_ETHERNET;
+                pAdapter = (*it).pAdapter;
+                if (pAdapter)
+                {
+                    info.enmStatus = pAdapter->OperStatus == IfOperStatusUp ? NETIF_S_UP : NETIF_S_DOWN;
+                    info.bIsDefault = (pAdapter->IfIndex == iDefault);
+                    info.bDhcpEnabled = pAdapter->Flags & IP_ADAPTER_DHCP_ENABLED;
+                    netIfFillInfoWithAddresses(&info, pAdapter);
+                }
                 else
-                    memcpy(Info.MACAddress.au8, pAdapter->PhysicalAddress, sizeof(Info.MACAddress));
-                Info.enmMediumType = NETIF_T_ETHERNET;
-                Info.enmStatus = pAdapter->OperStatus == IfOperStatusUp ? NETIF_S_UP : NETIF_S_DOWN;
-                Info.bDhcpEnabled = !!(pAdapter->Flags & IP_ADAPTER_DHCP_ENABLED);
-                Info.bIsDefault = (pAdapter->IfIndex == iDefault);
-
-                HostNetworkInterfaceType enmType;
-                WCHAR wszName[256];
-                /* Try to get name and type via Setup API */
-                getTypeAndName(pAdapter, &enmType, wszName, sizeof(wszName));
-
-                char *pszUuid = pAdapter->AdapterName + 1;
-                size_t len = strlen(pszUuid) - 1;
-                if (pszUuid[len] != '}')
-                {
-                    LogRel(("%s is not a valid UUID!\n", pAdapter->AdapterName));
-                    continue;
-                }
-                pszUuid[len] = 0;
-                rc = RTUuidFromStr(&Info.Uuid, pszUuid);
-                if (RT_FAILURE(rc))
-                {
-                    LogRel(("NetIfList: Failed to convert %s to UUID (%Rrc)\n", pszUuid, rc));
-                    continue;
-                }
-                LogRel(("Adding %ls as %s\n", pAdapter->Description,
-                        enmType == HostNetworkInterfaceType_Bridged ? "bridged" :
-                        enmType == HostNetworkInterfaceType_HostOnly ? "host-only" : "unknown"));
+                    info.enmStatus = NETIF_S_DOWN;
                 /* create a new object and add it to the list */
                 ComObjPtr<HostNetworkInterface> iface;
                 iface.createObject();
-                /* remove the curly bracket at the end */
-                rc = iface->init(wszName, enmType, &Info);
-                if (SUCCEEDED(rc))
-                {
-                    if (Info.bIsDefault)
+                HostNetworkInterfaceType enmType =
+                    _wcsnicmp((*it).pHwId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2) ?
+                    HostNetworkInterfaceType_Bridged : HostNetworkInterfaceType_HostOnly;
+                netIfLog(("Adding %ls as %s\n", (*it).pName,
+                        enmType == HostNetworkInterfaceType_Bridged ? "bridged" :
+                        enmType == HostNetworkInterfaceType_HostOnly ? "host-only" : "unknown"));
+                int rc = iface->init((*it).pName, enmType, &info);
+                if (FAILED(rc))
+                    netIfLog(("NetIfList: HostNetworkInterface::init() -> %Rrc\n", rc));
+                else
+                {
+                    if (info.bIsDefault)
                         list.push_front(iface);
                     else
                         list.push_back(iface);
                 }
-                else
-                {
-                    LogRel(("NetIfList: HostNetworkInterface::init() -> %Rrc\n", rc));
-                    Assert(0);
-                }
-            }
-        }
-    }
-
+                if ((*it).pHwId)
+                    CoTaskMemFree((*it).pHwId);
+                if ((*it).pName)
+                    CoTaskMemFree((*it).pName);
+            }
+        }
+    }
     RTMemFree(pAddresses);
 
-    return VINF_SUCCESS;
-}
-#endif /* !NETIF_WITHOUT_NETCFG */
+    return hr;
+}
