NetIf-win.cpp revision 79207ebc7bef44216ecdbe520de76317c713ada6
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * Main - NetIfList, Windows implementation.
9496b6f77d66eb89f088668752b8838d578d6e10vboxsync * Copyright (C) 2008-2012 Oracle Corporation
9496b6f77d66eb89f088668752b8838d578d6e10vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9496b6f77d66eb89f088668752b8838d578d6e10vboxsync * available from http://www.virtualbox.org. This file is free software;
9496b6f77d66eb89f088668752b8838d578d6e10vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9496b6f77d66eb89f088668752b8838d578d6e10vboxsync * General Public License (GPL) as published by the Free Software
9496b6f77d66eb89f088668752b8838d578d6e10vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync/*******************************************************************************
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync* Header Files *
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync*******************************************************************************/
53e1c27c7564c45ad0b92676ddea561591a3e869vboxsync pIpTable = (MIB_IPFORWARDTABLE *)RTMemAlloc(dwSize);
b459362b1c9b5ce5e6bf4ceb32ffe1294c08be07vboxsync if (GetIpForwardTable(pIpTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
53e1c27c7564c45ad0b92676ddea561591a3e869vboxsync pIpTable = (MIB_IPFORWARDTABLE *)RTMemAlloc(dwSize);
1826861f34e9be70b29cd5e1a6038caf9fbf37bevboxsync for (unsigned int i = 0; i < pIpTable->dwNumEntries; i++)
41e3b5da61b49017cb647f2f32a231c524fc370avboxsyncstatic int collectNetIfInfo(Bstr &strName, Guid &guid, PNETIFINFO pInfo, int iDefault)
f2ba84c335a6e7ac91f69863ff51b10c65c9d40fvboxsync * Most of the hosts probably have less than 10 adapters,
f2ba84c335a6e7ac91f69863ff51b10c65c9d40fvboxsync * so we'll mostly succeed from the first attempt.
f2ba84c335a6e7ac91f69863ff51b10c65c9d40fvboxsync PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)RTMemAlloc(uBufLen);
cfd41a3683178a30bac4417128b4673806653797vboxsync dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
693d9f3305eb4a4684a6613b8a41a6fa150cc101vboxsync /* Impressive! More than 10 adapters! Get more memory and try again. */
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync pAddresses = (PIP_ADAPTER_ADDRESSES)RTMemAlloc(uBufLen);
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
f2ba84c335a6e7ac91f69863ff51b10c65c9d40fvboxsync for (pAdapter = pAddresses; pAdapter; pAdapter = pAdapter->Next)
771761cda2c81e899526a0dce22c8cd2510fff82vboxsync for (pAddr = pAdapter->FirstUnicastAddress; pAddr; pAddr = pAddr->Next)
a2f6500ea77004e215d6fc8fcdab25b1d4d1ad3dvboxsync &((struct sockaddr_in *)pAddr->Address.lpSockaddr)->sin_addr.s_addr,
9c59bcefe2993070fafaf0d6cee9673f48479128vboxsync ((struct sockaddr_in6 *)pAddr->Address.lpSockaddr)->sin6_addr.s6_addr,
a2f6500ea77004e215d6fc8fcdab25b1d4d1ad3dvboxsync for (pPrefix = pAdapter->FirstPrefix; pPrefix; pPrefix = pPrefix->Next)
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync if (pPrefix->PrefixLength <= sizeof(pInfo->IPNetMask) * 8)
693d9f3305eb4a4684a6613b8a41a6fa150cc101vboxsync ASMBitSetRange(&pInfo->IPNetMask, 0, pPrefix->PrefixLength);
1826861f34e9be70b29cd5e1a6038caf9fbf37bevboxsync Log(("collectNetIfInfo: Unexpected IPv4 prefix length of %d\n",
62e5c2cfabb91397405d7bfe7908ec2b3a483831vboxsync if (pPrefix->PrefixLength <= sizeof(pInfo->IPv6NetMask) * 8)
8f7119688865a134053bd580972655ce2b8954b3vboxsync ASMBitSetRange(&pInfo->IPv6NetMask, 0, pPrefix->PrefixLength);
8f7119688865a134053bd580972655ce2b8954b3vboxsync Log(("collectNetIfInfo: Unexpected IPv6 prefix length of %d\n",
01f38d7bedc71f105edc6e67f8cbb9a0bf325442vboxsync if (sizeof(pInfo->MACAddress) != pAdapter->PhysicalAddressLength)
01f38d7bedc71f105edc6e67f8cbb9a0bf325442vboxsync Log(("collectNetIfInfo: Unexpected physical address length: %u\n", pAdapter->PhysicalAddressLength));
8f7119688865a134053bd580972655ce2b8954b3vboxsync memcpy(pInfo->MACAddress.au8, pAdapter->PhysicalAddress, sizeof(pInfo->MACAddress));
8f7119688865a134053bd580972655ce2b8954b3vboxsync pInfo->enmStatus = pAdapter->OperStatus == IfOperStatusUp ? NETIF_S_UP : NETIF_S_DOWN;
693d9f3305eb4a4684a6613b8a41a6fa150cc101vboxsync pInfo->bIsDefault = (pAdapter->IfIndex == iDefault);
693d9f3305eb4a4684a6613b8a41a6fa150cc101vboxsync HRESULT hr = VBoxNetCfgWinGetAdapterSettings((const GUID *)guid.raw(), &Settings);
693d9f3305eb4a4684a6613b8a41a6fa150cc101vboxsync/* svc helper func */
933606e7609b250f207a2f97112f8388f88998c1vboxsync /* for SVCHlpMsg::CreateHostOnlyNetworkInterface */
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync /* for SVCHlpMsg::RemoveHostOnlyNetworkInterface */
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsyncstatic HRESULT netIfNetworkInterfaceHelperClient(SVCHlpClient *aClient,
5f9ec43969b9ba00f6c2d03bafc9ac36a41c95e1vboxsync LogFlowFunc(("aClient={%p}, aProgress={%p}, aUser={%p}\n",
5f9ec43969b9ba00f6c2d03bafc9ac36a41c95e1vboxsync AssertReturn( (aClient == NULL && aProgress == NULL && aVrc == NULL)
5f9ec43969b9ba00f6c2d03bafc9ac36a41c95e1vboxsync || (aClient != NULL && aProgress != NULL && aVrc != NULL),
5f9ec43969b9ba00f6c2d03bafc9ac36a41c95e1vboxsync d(static_cast<NetworkInterfaceHelperClientData *>(aUser));
9ced981a0263f6280ccbf5dc64c0e81fbe4a2fdavboxsync /* "cleanup only" mode, just return (it will free aUser) */
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync LogFlowFunc(("CreateHostOnlyNetworkInterface:\n"));
53e1c27c7564c45ad0b92676ddea561591a3e869vboxsync LogFlowFunc(("Network connection name = '%ls'\n", d->name.raw()));
53e1c27c7564c45ad0b92676ddea561591a3e869vboxsync /* write message and parameters */
1826861f34e9be70b29cd5e1a6038caf9fbf37bevboxsync// vrc = aClient->write(Utf8Str(d->name));
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync// if (RT_FAILURE(vrc)) break;
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync /* wait for a reply */
1d258b8772ee104b5fab3d1743eabc2f5cfe2fa4vboxsync bool endLoop = false;
53e1c27c7564c45ad0b92676ddea561591a3e869vboxsync /* read the GUID */
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync LogFlowFunc(("Network connection GUID = {%RTuuid}\n", guid.raw()));
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync /* initialize the object returned to the caller by
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync * CreateHostOnlyNetworkInterface() */
77c85c820fe4467a0856134e0c9e5c5790cd847evboxsync rc = d->iface->init(Bstr(name), Bstr(name), guid, HostNetworkInterfaceType_HostOnly);
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync /* read the error message */
bc8ea11359bbfdee1aa1a32821d263292d4a8feevboxsync //"Invalid message code %d (%08lX)\n",
bc8ea11359bbfdee1aa1a32821d263292d4a8feevboxsync //reply, reply),
bc8ea11359bbfdee1aa1a32821d263292d4a8feevboxsync //rc = E_FAIL);
bc8ea11359bbfdee1aa1a32821d263292d4a8feevboxsync LogFlowFunc(("RemoveHostOnlyNetworkInterface:\n"));
bc8ea11359bbfdee1aa1a32821d263292d4a8feevboxsync LogFlowFunc(("Network connection GUID = {%RTuuid}\n", d->guid.raw()));
8f7119688865a134053bd580972655ce2b8954b3vboxsync /* write message and parameters */
bc8ea11359bbfdee1aa1a32821d263292d4a8feevboxsync /* wait for a reply */
8f7119688865a134053bd580972655ce2b8954b3vboxsync bool endLoop = false;
f2ba84c335a6e7ac91f69863ff51b10c65c9d40fvboxsync /* no parameters */
d95b7fbc09277b5375b98812fa76b08c6ce8535cvboxsync /* read the error message */
endLoop = true;
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
if (aVrc)
return rc;
switch (aMsgCode)
hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, guid.asOutParam(), name.asOutParam(), bstrErr.asOutParam());
return vrc;
return FALSE;
int iDefaultInterface)
Assert(0);
return rc;
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
&lpszApp);
if (uComponentStatus == 0)
else if (lpszApp)
return VINF_SUCCESS;
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
return VERR_GENERAL_FAILURE;
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
const char *pcszName)
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
d(new NetworkInterfaceHelperClientData());
static_cast<void *>(d.get()),
progress);
d.release();
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
d(new NetworkInterfaceHelperClientData());
static_cast<void *>(d.get()),
progress);
d.release();
int NetIfEnableStaticIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG ip, ULONG mask)
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
d(new NetworkInterfaceHelperClientData());
static_cast<void *>(d.get()),
progress);
d.release();
int NetIfEnableStaticIpConfigV6(VirtualBox *vBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
d(new NetworkInterfaceHelperClientData());
static_cast<void *>(d.get()),
progress);
d.release();
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
d(new NetworkInterfaceHelperClientData());
static_cast<void *>(d.get()),
progress);
d.release();
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
d(new NetworkInterfaceHelperClientData());
static_cast<void *>(d.get()),
progress);
d.release();
#ifndef VBOX_WITH_NETFLT
return VERR_NOT_IMPLEMENTED;
&lpszApp);
# ifdef VBOX_NETFLT_ONDEMAND_BIND
/* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
# ifndef VBOX_WITH_HARDENING
if (uComponentStatus == 0)
return VINF_SUCCESS;