Changeset 98293 in vbox for trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
- Timestamp:
- Jan 25, 2023 1:22:39 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
r98292 r98293 218 218 219 219 ADAPTER_SETTINGS Settings; 220 HRESULT hr = VBoxNetCfgWinGetAdapterSettings((const GUID *)guid.raw(), &Settings);221 if (hr == S_OK)220 HRESULT hrc = VBoxNetCfgWinGetAdapterSettings((const GUID *)guid.raw(), &Settings); 221 if (hrc == S_OK) 222 222 { 223 223 if (Settings.ip) … … 983 983 int iDefaultInterface) 984 984 { 985 LPWSTR lpszName;986 GUID IfGuid;987 HRESULT hr;988 985 int vrc = VERR_GENERAL_FAILURE; 989 986 990 hr = pncc->GetDisplayName(&lpszName); 991 Assert(hr == S_OK); 992 if (hr == S_OK) 987 LPWSTR lpszName; 988 HRESULT hrc = pncc->GetDisplayName(&lpszName); 989 Assert(hrc == S_OK); 990 if (hrc == S_OK) 993 991 { 994 992 Bstr name(lpszName); 995 993 996 hr = pncc->GetInstanceGuid(&IfGuid); 997 Assert(hr == S_OK); 998 if (hr == S_OK) 994 GUID IfGuid; 995 hrc = pncc->GetInstanceGuid(&IfGuid); 996 Assert(hrc == S_OK); 997 if (hrc == S_OK) 999 998 { 1000 999 Guid guidIfCopy(IfGuid); … … 1025 1024 } 1026 1025 else 1027 LogRelFunc(("failed to get device instance GUID (0x%x)\n", hr ));1026 LogRelFunc(("failed to get device instance GUID (0x%x)\n", hrc)); 1028 1027 CoTaskMemFree(lpszName); 1029 1028 } 1030 1029 else 1031 LogRelFunc(("failed to get device display name (0x%x)\n", hr ));1030 LogRelFunc(("failed to get device display name (0x%x)\n", hrc)); 1032 1031 1033 1032 return vrc; … … 1043 1042 return VERR_NOT_IMPLEMENTED; 1044 1043 #else /* # if defined VBOX_WITH_NETFLT */ 1045 INetCfgComponent *pMpNcc; 1046 HRESULT hr; 1047 IEnumNetCfgComponent *pEnumComponent; 1048 1049 hr = pNc->EnumComponents(&GUID_DEVCLASS_NET, &pEnumComponent); 1050 if (hr == S_OK) 1051 { 1052 while ((hr = pEnumComponent->Next(1, &pMpNcc, NULL)) == S_OK) 1044 IEnumNetCfgComponent *pEnumComponent; 1045 HRESULT hrc = pNc->EnumComponents(&GUID_DEVCLASS_NET, &pEnumComponent); 1046 if (hrc == S_OK) 1047 { 1048 INetCfgComponent *pMpNcc; 1049 while ((hrc = pEnumComponent->Next(1, &pMpNcc, NULL)) == S_OK) 1053 1050 { 1054 1051 LPWSTR pwszName; 1055 1052 ULONG uComponentStatus; 1056 hr = pMpNcc->GetDisplayName(&pwszName);1057 if (hr == S_OK)1053 hrc = pMpNcc->GetDisplayName(&pwszName); 1054 if (hrc == S_OK) 1058 1055 LogFunc(("%ls\n", pwszName)); 1059 1056 else 1060 LogRelFunc(("failed to get device display name (0x%x)\n", hr ));1061 hr = pMpNcc->GetDeviceStatus(&uComponentStatus);1062 if (hr == S_OK)1057 LogRelFunc(("failed to get device display name (0x%x)\n", hrc)); 1058 hrc = pMpNcc->GetDeviceStatus(&uComponentStatus); 1059 if (hrc == S_OK) 1063 1060 { 1064 1061 if (uComponentStatus == 0) 1065 1062 { 1066 1063 LPWSTR pId; 1067 hr = pMpNcc->GetId(&pId);1068 Assert(hr == S_OK);1069 if (hr == S_OK)1064 hrc = pMpNcc->GetId(&pId); 1065 Assert(hrc == S_OK); 1066 if (hrc == S_OK) 1070 1067 { 1071 1068 LogFunc(("id = %ls\n", pId)); 1072 1069 if (!_wcsnicmp(pId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2)) 1073 {1074 1070 vboxNetWinAddComponent(&list, pMpNcc, HostNetworkInterfaceType_HostOnly, -1); 1075 }1076 1071 CoTaskMemFree(pId); 1077 1072 } 1078 1073 else 1079 LogRelFunc(("failed to get device id (0x%x)\n", hr ));1074 LogRelFunc(("failed to get device id (0x%x)\n", hrc)); 1080 1075 } 1081 1076 } 1082 1077 else 1083 LogRelFunc(("failed to get device status (0x%x)\n", hr ));1078 LogRelFunc(("failed to get device status (0x%x)\n", hrc)); 1084 1079 pMpNcc->Release(); 1085 1080 } 1086 Assert(hr == S_OK || hr== S_FALSE);1081 Assert(hrc == S_OK || hrc == S_FALSE); 1087 1082 1088 1083 pEnumComponent->Release(); 1089 1084 } 1090 1085 else 1091 LogRelFunc(("EnumComponents error (0x%x)\n", hr ));1086 LogRelFunc(("EnumComponents error (0x%x)\n", hrc)); 1092 1087 #endif /* # if defined VBOX_WITH_NETFLT */ 1093 1088 return VINF_SUCCESS; … … 1100 1095 #else 1101 1096 Bstr name; 1102 HRESULT hr = pIf->COMGETTER(Name)(name.asOutParam());1103 if (hr == S_OK)1097 HRESULT hrc = pIf->COMGETTER(Name)(name.asOutParam()); 1098 if (hrc == S_OK) 1104 1099 { 1105 1100 Bstr IfGuid; 1106 hr = pIf->COMGETTER(Id)(IfGuid.asOutParam());1107 Assert(hr == S_OK);1108 if (hr == S_OK)1101 hrc = pIf->COMGETTER(Id)(IfGuid.asOutParam()); 1102 Assert(hrc == S_OK); 1103 if (hrc == S_OK) 1109 1104 { 1110 1105 memset(pInfo, 0, sizeof(NETIFINFO)); … … 1483 1478 static int netIfGetUnboundHostOnlyAdapters(INetCfg *pNetCfg, std::list<BoundAdapter> &adapters) 1484 1479 { 1485 INetCfgComponent *pMiniport; 1486 HRESULT hr; 1487 IEnumNetCfgComponent *pEnumComponent; 1488 1489 if ((hr = pNetCfg->EnumComponents(&GUID_DEVCLASS_NET, &pEnumComponent)) != S_OK) 1490 LogRelFunc(("failed to enumerate network adapter components (0x%x)\n", hr)); 1480 IEnumNetCfgComponent *pEnumComponent; 1481 HRESULT hrc = pNetCfg->EnumComponents(&GUID_DEVCLASS_NET, &pEnumComponent); 1482 if (hrc != S_OK) 1483 LogRelFunc(("failed to enumerate network adapter components (0x%x)\n", hrc)); 1491 1484 else 1492 1485 { 1493 while ((hr = pEnumComponent->Next(1, &pMiniport, NULL)) == S_OK) 1486 INetCfgComponent *pMiniport; 1487 while ((hrc = pEnumComponent->Next(1, &pMiniport, NULL)) == S_OK) 1494 1488 { 1495 1489 GUID guid; … … 1497 1491 struct BoundAdapter adapter; 1498 1492 memset(&adapter, 0, sizeof(adapter)); 1499 if ((hr = pMiniport->GetDisplayName(&adapter.pName)) != S_OK)1500 LogRelFunc(("failed to get device display name (0x%x)\n", hr ));1501 else if ((hr = pMiniport->GetDeviceStatus(&uComponentStatus)) != S_OK)1502 netIfLog(("failed to get device status (0x%x)\n", hr ));1493 if ((hrc = pMiniport->GetDisplayName(&adapter.pName)) != S_OK) 1494 LogRelFunc(("failed to get device display name (0x%x)\n", hrc)); 1495 else if ((hrc = pMiniport->GetDeviceStatus(&uComponentStatus)) != S_OK) 1496 netIfLog(("failed to get device status (0x%x)\n", hrc)); 1503 1497 else if (uComponentStatus != 0) 1504 1498 netIfLog(("wrong device status (0x%x)\n", uComponentStatus)); 1505 else if ((hr = pMiniport->GetId(&adapter.pHwId)) != S_OK)1506 LogRelFunc(("failed to get device id (0x%x)\n", hr ));1499 else if ((hrc = pMiniport->GetId(&adapter.pHwId)) != S_OK) 1500 LogRelFunc(("failed to get device id (0x%x)\n", hrc)); 1507 1501 else if (_wcsnicmp(adapter.pHwId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2)) 1508 1502 netIfLog(("not host-only id = %ls, ignored\n", adapter.pHwId)); 1509 else if ((hr = pMiniport->GetInstanceGuid(&guid)) != S_OK)1510 LogRelFunc(("failed to get instance id (0x%x)\n", hr ));1503 else if ((hrc = pMiniport->GetInstanceGuid(&guid)) != S_OK) 1504 LogRelFunc(("failed to get instance id (0x%x)\n", hrc)); 1511 1505 else 1512 1506 { … … 1522 1516 pMiniport->Release(); 1523 1517 } 1524 Assert(hr == S_OK || hr== S_FALSE);1518 Assert(hrc == S_OK || hrc == S_FALSE); 1525 1519 1526 1520 pEnumComponent->Release(); … … 1606 1600 static HRESULT netIfGetBoundAdapters(std::list<BoundAdapter> &boundAdapters) 1607 1601 { 1608 INetCfg *pNetCfg = NULL;1609 INetCfgComponent *pFilter;1610 LPWSTR lpszApp;1611 HRESULT hr;1612 1602 1613 1603 netIfLog(("building the list of interfaces\n")); 1614 1604 /* we are using the INetCfg API for getting the list of miniports */ 1615 hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, FALSE,1616 VBOX_APP_NAME,1617 10000,1618 &lpszApp);1619 Assert(hr == S_OK);1620 if (hr != S_OK)1621 {1622 LogRelFunc(("failed to query INetCfg (0x%x)\n", hr));1623 return hr;1624 } 1625 1626 if ((hr = pNetCfg->FindComponent(L"oracle_VBoxNetLwf", &pFilter)) != S_OK1605 INetCfg *pNetCfg = NULL; 1606 LPWSTR lpszApp = NULL; 1607 HRESULT hrc = VBoxNetCfgWinQueryINetCfg(&pNetCfg, FALSE, VBOX_APP_NAME, 10000, &lpszApp); 1608 Assert(hrc == S_OK); 1609 if (hrc != S_OK) 1610 { 1611 LogRelFunc(("failed to query INetCfg (0x%x)\n", hrc)); 1612 return hrc; 1613 } 1614 1615 INetCfgComponent *pFilter; 1616 if ((hrc = pNetCfg->FindComponent(L"oracle_VBoxNetLwf", &pFilter)) != S_OK 1627 1617 /* fall back to NDIS5 miniport lookup */ 1628 && (hr = pNetCfg->FindComponent(L"sun_VBoxNetFlt", &pFilter)))1629 LogRelFunc(("could not find either 'oracle_VBoxNetLwf' or 'sun_VBoxNetFlt' components (0x%x)\n", hr ));1618 && (hrc = pNetCfg->FindComponent(L"sun_VBoxNetFlt", &pFilter))) 1619 LogRelFunc(("could not find either 'oracle_VBoxNetLwf' or 'sun_VBoxNetFlt' components (0x%x)\n", hrc)); 1630 1620 else 1631 1621 { 1632 1622 INetCfgComponentBindings *pFilterBindings; 1633 1623 if ((pFilter->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pFilterBindings)) != S_OK) 1634 LogRelFunc(("failed to query INetCfgComponentBindings (0x%x)\n", hr ));1624 LogRelFunc(("failed to query INetCfgComponentBindings (0x%x)\n", hrc)); 1635 1625 else 1636 1626 { … … 1638 1628 INetCfgBindingPath *pBp; 1639 1629 if ((pFilterBindings->EnumBindingPaths(EBP_BELOW, &pEnumBp)) != S_OK) 1640 LogRelFunc(("failed to enumerate binding paths (0x%x)\n", hr ));1630 LogRelFunc(("failed to enumerate binding paths (0x%x)\n", hrc)); 1641 1631 else 1642 1632 { 1643 1633 pEnumBp->Reset(); 1644 while ((hr = pEnumBp->Next(1, &pBp, NULL)) == S_OK)1634 while ((hrc = pEnumBp->Next(1, &pBp, NULL)) == S_OK) 1645 1635 { 1646 1636 IEnumNetCfgBindingInterface *pEnumBi; … … 1649 1639 { 1650 1640 /** @todo some id of disabled path could be useful. */ 1651 netIfLog(("INetCfgBindingPath is disabled (0x%x)\n", hr ));1641 netIfLog(("INetCfgBindingPath is disabled (0x%x)\n", hrc)); 1652 1642 pBp->Release(); 1653 1643 continue; 1654 1644 } 1655 1645 if ((pBp->EnumBindingInterfaces(&pEnumBi)) != S_OK) 1656 LogRelFunc(("failed to enumerate binding interfaces (0x%x)\n", hr ));1646 LogRelFunc(("failed to enumerate binding interfaces (0x%x)\n", hrc)); 1657 1647 else 1658 1648 { 1659 hr = pEnumBi->Reset();1660 while ((hr = pEnumBi->Next(1, &pBi, NULL)) == S_OK)1649 hrc = pEnumBi->Reset(); 1650 while ((hrc = pEnumBi->Next(1, &pBi, NULL)) == S_OK) 1661 1651 { 1662 1652 INetCfgComponent *pAdapter; 1663 if ((hr = pBi->GetLowerComponent(&pAdapter)) != S_OK)1664 LogRelFunc(("failed to get lower component (0x%x)\n", hr ));1653 if ((hrc = pBi->GetLowerComponent(&pAdapter)) != S_OK) 1654 LogRelFunc(("failed to get lower component (0x%x)\n", hrc)); 1665 1655 else 1666 1656 { 1667 1657 LPWSTR pwszName = NULL; 1668 if ((hr = pAdapter->GetDisplayName(&pwszName)) != S_OK)1669 LogRelFunc(("failed to get display name (0x%x)\n", hr ));1658 if ((hrc = pAdapter->GetDisplayName(&pwszName)) != S_OK) 1659 LogRelFunc(("failed to get display name (0x%x)\n", hrc)); 1670 1660 else 1671 1661 { 1672 1662 ULONG uStatus; 1673 1663 DWORD dwChars; 1674 if ((hr = pAdapter->GetDeviceStatus(&uStatus)) != S_OK)1664 if ((hrc = pAdapter->GetDeviceStatus(&uStatus)) != S_OK) 1675 1665 netIfLog(("%ls: failed to get device status (0x%x)\n", 1676 pwszName, hr ));1677 else if ((hr = pAdapter->GetCharacteristics(&dwChars)) != S_OK)1666 pwszName, hrc)); 1667 else if ((hrc = pAdapter->GetCharacteristics(&dwChars)) != S_OK) 1678 1668 netIfLog(("%ls: failed to get device characteristics (0x%x)\n", 1679 pwszName, hr ));1669 pwszName, hrc)); 1680 1670 else if (uStatus != 0) 1681 1671 netIfLog(("%ls: wrong status 0x%x\n", … … 1688 1678 GUID guid; 1689 1679 LPWSTR pwszHwId = NULL; 1690 if ((hr = pAdapter->GetId(&pwszHwId)) != S_OK)1680 if ((hrc = pAdapter->GetId(&pwszHwId)) != S_OK) 1691 1681 LogRelFunc(("%ls: failed to get hardware id (0x%x)\n", 1692 pwszName, hr ));1682 pwszName, hrc)); 1693 1683 else if (!_wcsnicmp(pwszHwId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2)) 1694 1684 netIfLog(("host-only adapter %ls, ignored\n", pwszName)); 1695 else if ((hr = pAdapter->GetInstanceGuid(&guid)) != S_OK)1685 else if ((hrc = pAdapter->GetInstanceGuid(&guid)) != S_OK) 1696 1686 LogRelFunc(("%ls: failed to get instance GUID (0x%x)\n", 1697 pwszName, hr ));1687 pwszName, hrc)); 1698 1688 else 1699 1689 { … … 1894 1884 int NetIfList(std::list<ComObjPtr<HostNetworkInterface> > &list) 1895 1885 { 1896 HRESULT hr = S_OK;1897 1886 int iDefault = getDefaultInterfaceIndex(); 1898 1887 /* MSDN recommends to pre-allocate a 15KB buffer. */ … … 1911 1900 dwRc = GetAdaptersAddresses(AF_UNSPEC, NETIF_GAA_FLAGS, NULL, pAddresses, &uBufLen); 1912 1901 } 1902 HRESULT hrc; 1913 1903 if (dwRc != NO_ERROR) 1914 1904 { 1915 1905 LogRelFunc(("GetAdaptersAddresses failed (0x%x)\n", dwRc)); 1916 hr = HRESULT_FROM_WIN32(dwRc);1906 hrc = HRESULT_FROM_WIN32(dwRc); 1917 1907 } 1918 1908 else 1919 1909 { 1920 1910 std::list<BoundAdapter> boundAdapters; 1921 hr = netIfGetBoundAdapters(boundAdapters);1911 hrc = netIfGetBoundAdapters(boundAdapters); 1922 1912 #if 0 1923 if (hr != S_OK)1924 hr = netIfGetBoundAdaptersFallback(boundAdapters);1913 if (hrc != S_OK) 1914 hrc = netIfGetBoundAdaptersFallback(boundAdapters); 1925 1915 #endif 1926 if (hr != S_OK)1927 LogRelFunc(("netIfGetBoundAdapters failed (0x%x)\n", hr ));1916 if (hrc != S_OK) 1917 LogRelFunc(("netIfGetBoundAdapters failed (0x%x)\n", hrc)); 1928 1918 else 1929 1919 { … … 2008 1998 RTMemFree(pAddresses); 2009 1999 2010 return hr ;2011 } 2000 return hrc; 2001 }
Note:
See TracChangeset
for help on using the changeset viewer.