Changeset 57950 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Sep 29, 2015 6:15:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
r57639 r57950 1650 1650 1651 1651 #else /* !NETIF_WITHOUT_NETCFG */ 1652 1653 static void getTypeAndName(PIP_ADAPTER_ADDRESSES pAdapter, HostNetworkInterfaceType *enmType, PWCHAR pwszName, int cbName) 1654 { 1655 /* In case we fail to get the right values we initialize them with best-effort defaults. */ 1656 *enmType = wcsncmp(pAdapter->Description, L"VirtualBox", 10) == 0 1657 ? HostNetworkInterfaceType_HostOnly 1658 : HostNetworkInterfaceType_Bridged; 1659 wcscpy_s(pwszName, cbName / sizeof(*pwszName), pAdapter->Description); 1660 1661 char szKeyName[256]; 1662 sprintf_s(szKeyName, sizeof(szKeyName), 1663 "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", 1664 pAdapter->AdapterName); 1665 HKEY hkeyConnection; 1666 LONG status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hkeyConnection); 1667 if (status != ERROR_SUCCESS) 1668 { 1669 LogRel(("NetIf: Failed to find connection key in registry for %ls at %s\n", 1670 pAdapter->Description, szKeyName)); 1671 } 1672 else 1673 { 1674 WCHAR wszId[256]; 1675 DWORD dwLen = sizeof(wszId); 1676 status = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL, NULL, (LPBYTE)wszId, &dwLen); 1677 if (status != ERROR_SUCCESS) 1678 { 1679 LogRel(("NetIf: Failed to get PnPInstanceID from registry for %ls\n", pAdapter->Description)); 1680 } 1681 else 1682 { 1683 HDEVINFO hDevInfo = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_NET, NULL); 1684 if (hDevInfo != INVALID_HANDLE_VALUE) 1685 { 1686 SP_DEVINFO_DATA DevInfoData; 1687 1688 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA); 1689 if (SetupDiOpenDeviceInfo(hDevInfo, wszId, NULL, 0, &DevInfoData)) 1690 { 1691 if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, &DevInfoData, 1692 SPDRP_HARDWAREID, NULL, 1693 (PBYTE)wszId, sizeof(wszId), NULL)) 1694 { 1695 /* 1696 * We do not care for multiple strings that may have been 1697 * returned since our host-only adapter has a single id. 1698 */ 1699 if (_wcsnicmp(wszId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2)) 1700 *enmType = HostNetworkInterfaceType_Bridged; 1701 else 1702 *enmType = HostNetworkInterfaceType_HostOnly; 1703 } 1704 SetupDiGetDeviceRegistryPropertyW(hDevInfo, &DevInfoData, 1705 SPDRP_FRIENDLYNAME, NULL, 1706 (PBYTE)pwszName, cbName, NULL); 1707 } 1708 SetupDiDestroyDeviceInfoList(hDevInfo); 1709 } 1710 LogRel(("PnP ID: %ls\n", wszId)); 1711 } 1712 RegCloseKey(hkeyConnection); 1713 } 1714 } 1715 1652 1716 int NetIfList(std::list<ComObjPtr<HostNetworkInterface> > &list) 1653 1717 { … … 1691 1755 if (pAdapter->AdapterName[0] == '{') 1692 1756 { 1693 char *pszUuid = pAdapter->AdapterName + 1;1694 size_t len = strlen(pszUuid) - 1;1695 if (pszUuid[len] != '}')1696 {1697 LogRel(("%s is not a valid UUID!\n", pAdapter->AdapterName));1698 continue;1699 }1700 pszUuid[len] = 0;1701 rc = RTUuidFromStr(&Info.Uuid, pszUuid);1702 if (RT_FAILURE(rc))1703 {1704 LogRel(("NetIfList: Failed to convert %s to UUID (%Rrc)\n", pszUuid, rc));1705 continue;1706 }1707 1757 bool fIPv4Found, fIPv6Found; 1708 1758 PIP_ADAPTER_UNICAST_ADDRESS pAddr; … … 1779 1829 Info.bDhcpEnabled = !!(pAdapter->Flags & IP_ADAPTER_DHCP_ENABLED); 1780 1830 Info.bIsDefault = (pAdapter->IfIndex == iDefault); 1831 1781 1832 HostNetworkInterfaceType enmType; 1782 /* 1783 * For some reason, I would not even want to speculate what it is, the users see 1784 * adapter's description as its name in its property dialog box. 1785 */ 1786 enmType = wcsncmp(pAdapter->Description, L"VirtualBox", 10) == 0 1787 ? HostNetworkInterfaceType_HostOnly 1788 : HostNetworkInterfaceType_Bridged; 1789 Log(("Adding %ls as %s\n", pAdapter->Description, 1790 enmType == HostNetworkInterfaceType_Bridged ? "bridged" : "host-only")); 1833 WCHAR wszName[256]; 1834 /* Try to get name and type via Setup API */ 1835 getTypeAndName(pAdapter, &enmType, wszName, sizeof(wszName)); 1836 1837 char *pszUuid = pAdapter->AdapterName + 1; 1838 size_t len = strlen(pszUuid) - 1; 1839 if (pszUuid[len] != '}') 1840 { 1841 LogRel(("%s is not a valid UUID!\n", pAdapter->AdapterName)); 1842 continue; 1843 } 1844 pszUuid[len] = 0; 1845 rc = RTUuidFromStr(&Info.Uuid, pszUuid); 1846 if (RT_FAILURE(rc)) 1847 { 1848 LogRel(("NetIfList: Failed to convert %s to UUID (%Rrc)\n", pszUuid, rc)); 1849 continue; 1850 } 1851 LogRel(("Adding %ls as %s\n", pAdapter->Description, 1852 enmType == HostNetworkInterfaceType_Bridged ? "bridged" : 1853 enmType == HostNetworkInterfaceType_HostOnly ? "host-only" : "unknown")); 1791 1854 /* create a new object and add it to the list */ 1792 1855 ComObjPtr<HostNetworkInterface> iface; 1793 1856 iface.createObject(); 1794 1857 /* remove the curly bracket at the end */ 1795 rc = iface->init( pAdapter->Description, enmType, &Info);1858 rc = iface->init(wszName, enmType, &Info); 1796 1859 if (SUCCEEDED(rc)) 1797 1860 {
Note:
See TracChangeset
for help on using the changeset viewer.