Changeset 38797 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg
- Timestamp:
- Sep 20, 2011 9:37:07 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r38791 r38797 560 560 static VOID DoLogging(LPCSTR szString, ...) 561 561 { 562 LOG_ROUTINE p Routine = (LOG_ROUTINE)(*((void * volatile *)&g_Logger));563 if (p Routine)562 LOG_ROUTINE pfnRoutine = (LOG_ROUTINE)(*((void * volatile *)&g_Logger)); 563 if (pfnRoutine) 564 564 { 565 565 char szBuffer[4096] = {0}; 566 va_list pArgList;567 va_start( pArgList, szString);568 _vsnprintf(szBuffer, RT_ELEMENTS(szBuffer), szString, pArgList);569 va_end( pArgList);570 571 p Routine(szBuffer);566 va_list va; 567 va_start(va, szString); 568 _vsnprintf(szBuffer, RT_ELEMENTS(szBuffer), szString, va); 569 va_end(va); 570 571 pfnRoutine(szBuffer); 572 572 } 573 573 } … … 789 789 { 790 790 HRESULT hr; 791 WCHAR aQueryString[256];792 WCHAR GuidString[50];793 794 int length = StringFromGUID2(*pGuid, GuidString, sizeof(GuidString)/sizeof(GuidString[0]));791 WCHAR wszQuery[256]; 792 WCHAR wszGuid[50]; 793 794 int length = StringFromGUID2(*pGuid, wszGuid, RT_ELEMENTS(wszGuid)); 795 795 if (length) 796 796 { 797 swprintf( aQueryString, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", GuidString);797 swprintf(wszQuery, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", wszGuid); 798 798 IEnumWbemClassObject* pEnumerator = NULL; 799 hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(aQueryString), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); 799 hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(wszQuery), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 800 NULL, &pEnumerator); 800 801 if (SUCCEEDED(hr)) 801 802 { 802 IWbemClassObject *pclsObj;803 ULONG uReturn = 0;804 805 803 if (pEnumerator) 806 804 { 807 HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); 808 805 IWbemClassObject *pclsObj; 806 ULONG uReturn = 0; 807 hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); 808 NonStandardLogFlow(("netIfWinFindAdapterClassById: IEnumWbemClassObject::Next -> hr=0x%x pclsObj=%p uReturn=%u 42=%u\n", 809 hr, (void *)pclsObj, uReturn, 42)); 809 810 if (SUCCEEDED(hr)) 810 811 { 811 if (uReturn )812 if (uReturn && pclsObj != NULL) 812 813 { 814 *pAdapterConfig = pclsObj; 813 815 pEnumerator->Release(); 814 *pAdapterConfig = pclsObj; 815 hr = S_OK; 816 return hr; 816 NonStandardLogFlow(("netIfWinFindAdapterClassById: S_OK and %p\n", *pAdapterConfig)); 817 return S_OK; 817 818 } 818 else 819 { 820 hr = S_FALSE; 821 } 819 820 hr = E_FAIL; 822 821 } 823 822 824 823 pEnumerator->Release(); 824 } 825 else 826 { 827 NonStandardLogFlow(("ExecQuery returned no enumerator\n")); 828 hr = E_FAIL; 825 829 } 826 830 } … … 831 835 { 832 836 DWORD winEr = GetLastError(); 833 NonStandardLogFlow(("StringFromGUID2 failed winEr (%d)\n", winEr));834 837 hr = HRESULT_FROM_WIN32( winEr ); 835 } 836 838 if (SUCCEEDED(hr)) 839 hr = E_FAIL; 840 NonStandardLogFlow(("StringFromGUID2 failed winEr=%u, hr=0x%x\n", winEr, hr)); 841 } 842 843 NonStandardLogFlow(("netIfWinFindAdapterClassById: 0x%x and %p\n", hr, *pAdapterConfig)); 837 844 return hr; 838 845 } … … 844 851 VariantInit(&vtServiceName); 845 852 846 HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0 , &vtServiceName, 0, 0);853 HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0 /*lFlags*/, &vtServiceName, NULL /*pvtType*/, NULL /*plFlavor*/); 847 854 if (SUCCEEDED(hr)) 848 855 { 849 *pbIsHostOnly = (bstr_t(vtServiceName.bstrVal) == bstr_t("VBoxNetAdp"));856 *pbIsHostOnly = bstr_t(vtServiceName.bstrVal) == bstr_t("VBoxNetAdp"); 850 857 851 858 VariantClear(&vtServiceName); … … 985 992 for (i = 0; 986 993 (hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam())) == S_OK 987 988 989 990 994 && (hr = netIfWinHasIpSettings(pAdapterConfig, pCheckIp, pCheckMask, pFound)) == S_OK 995 && !(*pFound) 996 && i < sec2Wait/6; 997 i++) 991 998 { 992 999 Sleep(6000); … … 1457 1464 if (SUCCEEDED(hr)) 1458 1465 { 1459 ComPtr 1466 ComPtr<IWbemClassObject> pAdapterConfig; 1460 1467 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1461 1468 if (SUCCEEDED(hr)) … … 1471 1478 1472 1479 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinIsDhcpEnabled(const GUID * pGuid, BOOL *pEnabled) 1480 { 1481 HRESULT hr; 1482 ComPtr <IWbemServices> pSvc; 1483 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 1484 if (SUCCEEDED(hr)) 1485 { 1486 ComPtr<IWbemClassObject> pAdapterConfig; 1487 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1488 if (SUCCEEDED(hr)) 1489 { 1490 VARIANT vtEnabled; 1491 hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0); 1492 if (SUCCEEDED(hr)) 1493 *pEnabled = vtEnabled.boolVal; 1494 } 1495 } 1496 1497 return hr; 1498 } 1499 1500 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableStaticIpConfig(IN const GUID *pGuid, IN ULONG ip, IN ULONG mask) 1501 { 1502 NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: ip=0x%x mask=0x%x", ip, mask)); 1503 ComPtr<IWbemServices> pSvc; 1504 HRESULT hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 1505 if (SUCCEEDED(hr)) 1506 { 1507 ComPtr<IWbemClassObject> pAdapterConfig; 1508 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1509 if (SUCCEEDED(hr)) 1510 { 1511 BOOL bIsHostOnly; 1512 hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly); 1513 if (SUCCEEDED(hr)) 1514 { 1515 if (bIsHostOnly) 1516 { 1517 in_addr aIp[1]; 1518 in_addr aMask[1]; 1519 aIp[0].S_un.S_addr = ip; 1520 aMask[0].S_un.S_addr = mask; 1521 1522 BSTR ObjPath; 1523 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 1524 if (SUCCEEDED(hr)) 1525 { 1526 hr = netIfWinEnableStaticV4(pSvc, pGuid, ObjPath, aIp, aMask, ip != 0 ? 1 : 0); 1527 if (SUCCEEDED(hr)) 1528 { 1529 #if 0 1530 in_addr aGw[1]; 1531 aGw[0].S_un.S_addr = gw; 1532 hr = netIfWinSetGatewaysV4(pSvc, ObjPath, aGw, 1); 1533 if (SUCCEEDED(hr)) 1534 #endif 1535 { 1536 } 1537 } 1538 SysFreeString(ObjPath); 1539 } 1540 } 1541 else 1542 { 1543 hr = E_FAIL; 1544 } 1545 } 1546 } 1547 } 1548 1549 NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: returns 0x%x", hr)); 1550 return hr; 1551 } 1552 1553 #if 0 1554 static HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway) 1473 1555 { 1474 1556 HRESULT hr; … … 1477 1559 if (SUCCEEDED(hr)) 1478 1560 { 1479 ComPtr <IWbemClassObject> pAdapterConfig; 1480 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1481 if (SUCCEEDED(hr)) 1482 { 1483 VARIANT vtEnabled; 1484 hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0); 1485 if (SUCCEEDED(hr)) 1486 *pEnabled = vtEnabled.boolVal; 1487 } 1488 } 1489 1490 return hr; 1491 } 1492 1493 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableStaticIpConfig(IN const GUID *pGuid, IN ULONG ip, IN ULONG mask) 1494 { 1495 HRESULT hr; 1496 ComPtr <IWbemServices> pSvc; 1497 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 1498 if (SUCCEEDED(hr)) 1499 { 1500 ComPtr <IWbemClassObject> pAdapterConfig; 1501 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1502 if (SUCCEEDED(hr)) 1503 { 1504 BOOL bIsHostOnly; 1505 hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly); 1506 if (SUCCEEDED(hr)) 1507 { 1508 if (bIsHostOnly) 1509 { 1510 in_addr aIp[1]; 1511 in_addr aMask[1]; 1512 aIp[0].S_un.S_addr = ip; 1513 aMask[0].S_un.S_addr = mask; 1514 1515 BSTR ObjPath; 1516 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 1517 if (SUCCEEDED(hr)) 1518 { 1519 hr = netIfWinEnableStaticV4(pSvc, pGuid, ObjPath, aIp, aMask, ip != 0 ? 1 : 0); 1520 if (SUCCEEDED(hr)) 1521 { 1522 #if 0 1523 in_addr aGw[1]; 1524 aGw[0].S_un.S_addr = gw; 1525 hr = netIfWinSetGatewaysV4(pSvc, ObjPath, aGw, 1); 1526 if (SUCCEEDED(hr)) 1527 #endif 1528 { 1529 } 1530 } 1531 SysFreeString(ObjPath); 1532 } 1533 } 1534 else 1535 { 1536 hr = E_FAIL; 1537 } 1538 } 1539 } 1540 } 1541 1542 return hr; 1543 } 1544 1545 #if 0 1546 static HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway) 1547 { 1548 HRESULT hr; 1549 ComPtr <IWbemServices> pSvc; 1550 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 1551 if (SUCCEEDED(hr)) 1552 { 1553 ComPtr <IWbemClassObject> pAdapterConfig; 1561 ComPtr<IWbemClassObject> pAdapterConfig; 1554 1562 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1555 1563 if (SUCCEEDED(hr)) … … 1599 1607 if (SUCCEEDED(hr)) 1600 1608 { 1601 ComPtr 1609 ComPtr<IWbemClassObject> pAdapterConfig; 1602 1610 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1603 1611 if (SUCCEEDED(hr)) … … 1636 1644 { 1637 1645 HRESULT hr; 1638 ComPtr <IWbemServices> pSvc; 1639 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 1646 ComPtr <IWbemServices> pSvc; 1647 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 1648 if (SUCCEEDED(hr)) 1649 { 1650 ComPtr<IWbemClassObject> pAdapterConfig; 1651 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1640 1652 if (SUCCEEDED(hr)) 1641 1653 { 1642 ComPtr <IWbemClassObject> pAdapterConfig;1643 hr = netIfWin FindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());1654 BOOL bIsHostOnly; 1655 hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly); 1644 1656 if (SUCCEEDED(hr)) 1645 1657 { 1646 BOOL bIsHostOnly;1647 hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);1648 if (SUCCEEDED(hr))1649 {1650 if ( bIsHostOnly)1658 if (bIsHostOnly) 1659 { 1660 BSTR ObjPath; 1661 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 1662 if (SUCCEEDED(hr)) 1651 1663 { 1652 BSTR ObjPath; 1653 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 1664 hr = netIfWinDhcpRediscover(pSvc, ObjPath); 1654 1665 if (SUCCEEDED(hr)) 1655 1666 { 1656 hr = netIfWinDhcpRediscover(pSvc, ObjPath); 1657 if (SUCCEEDED(hr)) 1658 { 1659 // hr = netIfWinUpdateConfig(pIf); 1660 } 1661 SysFreeString(ObjPath); 1667 //hr = netIfWinUpdateConfig(pIf); 1662 1668 } 1669 SysFreeString(ObjPath); 1663 1670 } 1664 else 1665 { 1666 hr = E_FAIL; 1667 } 1668 } 1669 } 1670 } 1671 } 1672 else 1673 { 1674 hr = E_FAIL; 1675 } 1676 } 1677 } 1678 } 1671 1679 1672 1680 … … 2152 2160 { 2153 2161 WCHAR strRegLocation [256]; 2154 WCHAR GuidString[50];2155 2156 int length = StringFromGUID2(*pGUID, GuidString, sizeof(GuidString)/sizeof(GuidString[0]));2162 WCHAR wszGuid[50]; 2163 2164 int length = StringFromGUID2(*pGUID, wszGuid, RT_ELEMENTS(wszGuid)); 2157 2165 if (!length) 2158 2166 SetErrBreak(("Failed to create a Guid string")); … … 2161 2169 L"SYSTEM\\CurrentControlSet\\Control\\Network\\" 2162 2170 L"{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", 2163 GuidString);2171 wszGuid); 2164 2172 2165 2173 LONG status; … … 2637 2645 KEY_READ); 2638 2646 if (hkey == INVALID_HANDLE_VALUE) 2639 SetErrBreak (("SetupDiOpenDevRegKey failed (0x%08X)", 2640 GetLastError())); 2641 2642 cbSize = sizeof (pWCfgGuidString); 2647 SetErrBreak(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError())); 2648 2649 cbSize = sizeof(pWCfgGuidString); 2643 2650 DWORD ret; 2644 2651 ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL,
Note:
See TracChangeset
for help on using the changeset viewer.