NetIfList-win.cpp revision 358d4cfb752e5f92ccbd283131fa0bb2fe0f90b2
/* $Id$ */
/** @file
* Main - NetIfList, Windows implementation.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_MAIN
#include <list>
#define _WIN32_DCOM
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#ifdef VBOX_WITH_NETFLT
#include "VBox/WinNetConfig.h"
#include "devguid.h"
#endif
#include <iphlpapi.h>
#include "Logging.h"
#include "HostNetworkInterfaceImpl.h"
#include "netif.h"
#ifdef VBOX_WITH_NETFLT
#include <Wbemidl.h>
#include <comdef.h>
{
// Step 3: ---------------------------------------------------
// Obtain the initial locator to WMI -------------------------
0,
{
// Step 4: -----------------------------------------------------
// Connect to WMI through the IWbemLocator::ConnectServer method
// Connect to the root\cimv2 namespace with
// the current user and obtain pointer pSvc
// to make IWbemServices calls.
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
{
LogRel(("Connected to ROOT\\CIMV2 WMI namespace\n"));
// Step 5: --------------------------------------------------
// Set security levels on the proxy -------------------------
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
{
/* do not need it any more */
return hres;
}
else
{
}
}
else
{
}
}
else
{
// CoUninitialize();
}
return hres;
}
static HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, GUID * pGuid, IWbemClassObject **pAdapterConfig)
{
char uuidStr[RTUUID_STR_LENGTH];
if(RT_SUCCESS(rc))
{
swprintf(aQueryString, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"{%S}\"", uuidStr);
// Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ----
bstr_t("WQL"),
NULL,
&pEnumerator);
{
// Step 7: -------------------------------------------------
// Get the data from the query in step 6 -------------------
while (pEnumerator)
{
{
if(uReturn)
{
pEnumerator->Release();
return hres;
}
else
{
}
}
}
pEnumerator->Release();
}
else
{
}
}
else
{
hres = -1;
}
return hres;
}
{
// Get the value of the key property
{
}
else
{
Assert(0);
}
return hr;
}
)
{
// Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ----
{
{
{
// Store the value for the in parameters
pArgs[i], 0);
{
break;
}
}
{
{
}
}
}
}
return hres;
}
{
if(pIpArray)
{
{
long aIndex[1];
aIndex[0] = i;
{
break;
}
}
{
}
}
else
{
Assert(0);
}
return hr;
}
{
if(pIpArray)
{
long aIndex[1];
aIndex[0] = 0;
{
}
{
}
}
else
{
Assert(0);
}
return hr;
}
{
{
}
return hr;
}
{
{
}
return hr;
}
static HRESULT netIfWinEnableStatic(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pIp, VARIANT * pMask)
{
if(ClassName)
{
{
{
}
}
}
else
{
Assert(0);
}
return hr;
}
static HRESULT netIfWinEnableStaticV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aIp, in_addr * aMask, UINT cIp)
{
{
{
}
}
return hr;
}
{
{
{
}
}
return hr;
}
/* win API allows to set gw metrics as well, we are not setting them */
{
if(ClassName)
{
{
{
}
}
}
else
{
Assert(0);
}
return hr;
}
/* win API allows to set gw metrics as well, we are not setting them */
{
{
}
return hr;
}
/* win API allows to set gw metrics as well, we are not setting them */
{
{
VariantClear(&vGw);
}
return hr;
}
{
if(ClassName)
{
{
{
}
}
}
else
{
Assert(0);
}
return hr;
}
{
/*
* Most of the hosts probably have less than 10 adapters,
* so we'll mostly succeed from the first attempt.
*/
if (!pAddresses)
return VERR_NO_MEMORY;
if (dwRc == ERROR_BUFFER_OVERFLOW)
{
/* Impressive! More than 10 adapters! Get more memory and try again. */
if (!pAddresses)
return VERR_NO_MEMORY;
}
{
{
{
{
bool fIPFound, fIPv6Found;
fIPFound = fIPv6Found = false;
{
{
case AF_INET:
if (!fIPFound)
{
fIPFound = true;
}
break;
case AF_INET6:
if (!fIPv6Found)
{
fIPv6Found = true;
sizeof(pInfo->IPv6Address));
}
break;
}
}
fIPFound = fIPv6Found = false;
{
{
case AF_INET:
if (!fIPFound)
{
fIPFound = true;
}
break;
case AF_INET6:
if (!fIPv6Found)
{
fIPv6Found = true;
}
break;
}
}
Log(("collectNetIfInfo: Unexpected physical address length: %u\n", pAdapter->PhysicalAddressLength));
else
break;
}
}
}
}
return VINF_SUCCESS;
}
{
{
{
if (RT_SUCCESS(rc))
{
}
else
{
}
}
}
return hr;
}
{
{
{
{
{
{
{
}
}
}
}
}
}
}
int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)
{
{
{
{
{
{
{
}
}
}
}
}
}
}
int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway)
{
return VERR_GENERAL_FAILURE;
}
{
{
{
{
{
{
}
}
}
}
}
}
# define VBOX_APP_NAME L"VirtualBox"
static int vboxNetWinAddComponent(std::list <ComObjPtr <HostNetworkInterface> > * pPist, INetCfgComponent * pncc, HostNetworkInterfaceType enmType)
{
int rc = VERR_GENERAL_FAILURE;
{
{
if (RT_FAILURE(rc))
{
}
/* create a new object and add it to the list */
/* remove the curly bracket at the end */
{
rc = VINF_SUCCESS;
}
else
{
Assert(0);
}
}
}
return rc;
}
#else /* #ifndef VBOX_WITH_NETFLT */
/**
* Windows helper function for NetIfList().
*
* @returns true / false.
*
* @param guid The GUID.
*/
static bool IsTAPDevice(const char *guid)
{
int i = 0;
bool ret = false;
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &hNetcard);
if (status != ERROR_SUCCESS)
return false;
for (;;)
{
char szEnumName[256];
char szNetCfgInstanceId[256];
len = sizeof(szEnumName);
if (status != ERROR_SUCCESS)
break;
if (status == ERROR_SUCCESS)
{
len = sizeof(szNetCfgInstanceId);
status = RegQueryValueExA(hNetCardGUID, "NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
{
char szNetProductName[256];
char szNetProviderName[256];
szNetProductName[0] = 0;
len = sizeof(szNetProductName);
status = RegQueryValueExA(hNetCardGUID, "ProductName", NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
szNetProviderName[0] = 0;
len = sizeof(szNetProviderName);
status = RegQueryValueExA(hNetCardGUID, "ProviderName", NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
{
ret = true;
break;
}
}
}
++i;
}
return ret;
}
#endif /* #ifndef VBOX_WITH_NETFLT */
{
#ifndef VBOX_WITH_NETFLT
/* VBoxNetAdp is available only when VBOX_WITH_NETFLT is enabled */
return VERR_NOT_IMPLEMENTED;
#else /* # if defined VBOX_WITH_NETFLT */
/* we are using the INetCfg API for getting the list of miniports */
&pNc,
&lpszApp );
{
{
{
//#ifndef DEBUG_bird
// Assert(hr == S_OK);
//#endif
{
if(uComponentStatus == 0)
{
{
{
}
}
}
}
}
}
else
{
}
}
else if(lpszApp)
{
}
#endif /* # if defined VBOX_WITH_NETFLT */
return VINF_SUCCESS;
}
{
#ifndef VBOX_WITH_NETFLT
static const char *NetworkKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\"
"{4D36E972-E325-11CE-BFC1-08002BE10318}";
if (status != ERROR_SUCCESS)
{
return E_FAIL;
}
for (int i = 0;; ++ i)
{
char szNetworkGUID [256];
char szNetworkConnection [256];
len = sizeof (szNetworkGUID);
if (status != ERROR_SUCCESS)
break;
if (!IsTAPDevice(szNetworkGUID))
continue;
"%s\\Connection", szNetworkGUID);
if (status == ERROR_SUCCESS)
{
{
if (status == ERROR_SUCCESS)
{
/* put a trailing zero, just in case (see MSDN) */
/* create a new object and add it to the list */
/* remove the curly bracket at the end */
if (RT_FAILURE(rc))
{
}
}
}
}
}
#else /* # if defined VBOX_WITH_NETFLT */
/* we are using the INetCfg API for getting the list of miniports */
&pNc,
&lpszApp );
{
# ifdef VBOX_NETFLT_ONDEMAND_BIND
/* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
# else
/* for the filter-based approach we get all miniports our filter (sun_VBoxNetFlt)is bound to */
# ifndef VBOX_WITH_HARDENING
{
/* TODO: try to install the netflt from here */
}
# endif
# endif
{
{
{
/* S_OK == enabled, S_FALSE == disabled */
{
{
{
{
//#ifndef DEBUG_bird
// Assert(hr == S_OK);
//#endif
{
if(uComponentStatus == 0)
{
}
}
}
}
}
}
}
}
}
else
{
}
}
#endif /* # if defined VBOX_WITH_NETFLT */
return VINF_SUCCESS;
}