static HRESULT vboxNetFltWinNotifyShouldBind(IN INetCfgBindingPath *pPath, OUT bool *pbDoBind) { IEnumNetCfgBindingInterface *pEnumBindingIf; HRESULT hr = pPath->EnumBindingInterfaces(&pEnumBindingIf); if (hr == S_OK) { hr = pEnumBindingIf->Reset(); if (hr == S_OK) { ULONG ulCount; INetCfgBindingInterface *pBindingIf; do { hr = pEnumBindingIf->Next(1, &pBindingIf, &ulCount); if (hr == S_OK) { hr = vboxNetFltWinNotifyShouldBind(pBindingIf, pbDoBind); pBindingIf->Release(); if (hr == S_OK) { if (!(*pbDoBind)) { break; } } else { /* break on failure */ break; } } else if (hr == S_FALSE) { /* no more elements */ hr = S_OK; break; } else { NonStandardAssertBreakpoint(); /* break on falure */ break; } } while (true); } else { NonStandardAssertBreakpoint(); } pEnumBindingIf->Release(); } else { NonStandardAssertBreakpoint(); } return hr; }
void DumpBindingPath (INetCfgBindingPath *pncbp) { LPWSTR lpsz; HRESULT hr; #ifdef VERBOSE_TRACE INetCfgComponent *pncc; IEnumNetCfgBindingInterface *pencbi; INetCfgBindingInterface *pncbi; DWORD dwIndex; ULONG ulCount; #endif #pragma prefast(suppress:26035, "&lpsz is a pointer to a buffer that receives a constant null-terminated string, see http://msdn.microsoft.com/en-us/library/ms805810.aspx") hr = pncbp->GetPathToken( &lpsz ); if ( hr == S_OK ) { TraceMsg( L" BindingPath: %s\n", lpsz ); CoTaskMemFree( lpsz ); } else { TraceMsg( L" BindingPath: GetPathToken failed(HRESULT %x).\n", hr ); } #ifdef VERBOSE_TRACE hr = pncbp->EnumBindingInterfaces( &pencbi ); if ( hr == S_OK ) { hr = pencbi ->Next( 1, &pncbi, &ulCount ); for (dwIndex=0; hr == S_OK; dwIndex++ ) { hr = pncbi->GetName( &lpsz ); if ( hr == S_OK ) { TraceMsg( L" BindingInterface(%d): %s\n", dwIndex, lpsz ); CoTaskMemFree( lpsz ); } else { TraceMsg( L" BindingInterface(%d): GetName failed(HRESULT %x).\n", dwIndex, hr ); } hr = pncbi->GetUpperComponent( &pncc ); if ( hr == S_OK ) { TraceMsg( L" \tUpperComponent of the interface(%d)...\n", dwIndex ); DumpComponent( pncc ); ReleaseObj( pncc ); } else { TraceMsg( L" UpperComponent: GetUpperComponent failed(HRESULT = %x).\n", hr ); } hr = pncbi->GetLowerComponent( &pncc ); if ( hr == S_OK ) { TraceMsg( L" \tLowerComponent of the interface(%d)...\n", dwIndex ); DumpComponent( pncc ); ReleaseObj( pncc ); } else { TraceMsg( L" LowerComponent: GetLowerComponent failed(HRESULT = %x).\n", hr ); } ReleaseObj( pncbi ); hr = pencbi ->Next( 1, &pncbi, &ulCount ); } ReleaseObj( pencbi ); } else { TraceMsg( L" EnumBindingInterfaces failed, (HRESULT = %x)\n", hr ); } #endif return; }
//+--------------------------------------------------------------------------- // // Function: HrShowBindingPath // // Purpose: Display components of a binding path in the format: // foo -> bar -> adapter // // Arguments: // pncbp [in] pointer to INetCfgBindingPath object // // Returns: S_OK on success, otherwise an error code // // Notes: // HRESULT HrShowBindingPath(IN INetCfgBindingPath* pncbp) { HRESULT hr=S_OK; INetCfgBindingInterface* pncbi; INetCfgComponent* pncc = NULL; BOOL fFirstInterface=TRUE; PWSTR szComponentId; while (SUCCEEDED(hr) && (S_OK == (hr = HrGetNextBindingInterface(pncbp, &pncbi)))) { // for the first (top) interface we need to get the upper as well as // the lower component. for other interfaces we need to get // only the lower component. if (fFirstInterface) { fFirstInterface = FALSE; hr = pncbi->GetUpperComponent(&pncc); if (SUCCEEDED(hr)) { // get id so that we can display it // // for readability of the output, we have used the GetId // function. For non net class components, this // does not pose a problem. In case of net class components, // there may be more than one net adapters of the same type // in which case, GetId will return the same string. This will // make it impossible to distinguish between two binding // paths that end in two distinct identical cards. In such case, // it may be better to use the GetInstanceGuid function because // it will return unique GUID for each instance of an adapter. // hr = pncc->GetId(&szComponentId); ReleaseObj(pncc); if (SUCCEEDED(hr)) { LogPrintf(szComponentId); CoTaskMemFree(szComponentId); } } } if (SUCCEEDED(hr)) { hr = pncbi->GetLowerComponent(&pncc); if (SUCCEEDED(hr)) { hr = pncc->GetId(&szComponentId); if (SUCCEEDED(hr)) { LogPrintf(_T(" -> %s"), szComponentId); CoTaskMemFree(szComponentId); } ReleaseObj(pncc); } } ReleaseObj(pncbi); } LogPrintf(_T("\n")); if (hr == S_FALSE) { hr = S_OK; } return hr; }