NetIfList-win.cpp revision f0bd2e30dcb24481478eda6d824346b4eb1198ce
/* $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"
{
/*
* 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;
}
#ifdef VBOX_WITH_NETFLT
# define VBOX_APP_NAME L"VirtualBox"
static int vboxNetWinAddComponent(std::list <ComObjPtr <HostNetworkInterface> > * pPist, INetCfgComponent * pncc, bool bReal)
{
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
#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;
}