NetIf-generic.cpp revision b78a2ee0977fced6695499928b445995ecacfbc0
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync/* $Id$ */
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync/** @file
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * VirtualBox Main - Generic NetIf implementation.
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync */
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync/*
8502773207230763deba3e622495f2099398dcb0vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync *
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * available from http://www.virtualbox.org. This file is free software;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * General Public License (GPL) as published by the Free Software
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync *
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync * additional information or have any questions.
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync */
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include <VBox/err.h>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include <VBox/log.h>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include <iprt/process.h>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include <iprt/env.h>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include <iprt/path.h>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include <iprt/param.h>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync# include <cstdio>
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#endif
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include "HostNetworkInterfaceImpl.h"
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include "ProgressImpl.h"
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include "VirtualBoxImpl.h"
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#include "netif.h"
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#define VBOXNETADPCTL_NAME "VBoxNetAdpCtl"
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncstatic int NetIfAdpCtl(const char * pcszIfName, const char *pszAddr, const char *pszOption, const char *pszMask)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync const char *args[] = { NULL, pcszIfName, pszAddr, pszOption, pszMask, NULL };
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync char szAdpCtl[RTPATH_MAX];
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME));
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (RT_FAILURE(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync LogRel(("NetIfAdpCtl: failed to get program path, rc=%Vrc.\n", rc));
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return rc;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync args[0] = szAdpCtl;
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync if (!RTPathExists(szAdpCtl))
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync LogRel(("NetIfAdpCtl: path %s does not exist. Failed to run " VBOXNETADPCTL_NAME " helper.\n",
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync szAdpCtl));
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_FILE_NOT_FOUND;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync RTPROCESS pid;
8502773207230763deba3e622495f2099398dcb0vboxsync rc = RTProcCreate(szAdpCtl, args, RTENV_DEFAULT, 0, &pid);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (RT_SUCCESS(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync RTPROCSTATUS Status;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync rc = RTProcWait(pid, 0, &Status);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if ( RT_SUCCESS(rc)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync && Status.iStatus == 0
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync && Status.enmReason == RTPROCEXITREASON_NORMAL)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VINF_SUCCESS;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync LogRel(("NetIfAdpCtl: failed to create process for %.\n",
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync szAdpCtl));
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return rc;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncstatic int NetIfAdpCtl(HostNetworkInterface * pIf, const char *pszAddr, const char *pszOption, const char *pszMask)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync Bstr interfaceName;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pIf->COMGETTER(Name)(interfaceName.asOutParam());
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync Utf8Str strName(interfaceName);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return NetIfAdpCtl(strName, pszAddr, pszOption, pszMask);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfEnableStaticIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync const char *pszOption, *pszMask;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync char szAddress[16]; /* 4*3 + 3*1 + 1 */
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync char szNetMask[16]; /* 4*3 + 3*1 + 1 */
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync uint8_t *pu8Addr = (uint8_t *)&aNewIp;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync uint8_t *pu8Mask = (uint8_t *)&aMask;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (aNewIp == 0)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pu8Addr = (uint8_t *)&aOldIp;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pszOption = "remove";
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pszMask = NULL;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pszOption = "netmask";
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pszMask = szNetMask;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d",
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d",
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return NetIfAdpCtl(pIf, szAddress, pszOption, pszMask);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfEnableStaticIpConfigV6(VirtualBox * /* vBox */, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync char szAddress[5*8 + 1 + 5 + 1];
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (Bstr(aIPV6Address).length())
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d",
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync aIPV6Address, aIPV6MaskPrefixLength);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return NetIfAdpCtl(pIf, szAddress, NULL, NULL);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync RTStrPrintf(szAddress, sizeof(szAddress), "%ls",
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync aOldIPV6Address);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return NetIfAdpCtl(pIf, szAddress, "remove", NULL);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfEnableDynamicIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * /* pIf */)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_NOT_IMPLEMENTED;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync /* create a progress object */
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync ComObjPtr <Progress> progress;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress.createObject();
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync ComPtr<IHost> host;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if(SUCCEEDED(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync rc = progress->init (pVBox, host,
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync Bstr ("Creating host only network interface"),
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync FALSE /* aCancelable */);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if(SUCCEEDED(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync CheckComRCReturnRC (rc);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress.queryInterfaceTo (aProgress);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync char szAdpCtl[RTPATH_MAX];
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME " add"));
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (RT_FAILURE(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(),
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync "Failed to get program path, rc=%Vrc.\n", rc);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return rc;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " add");
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync FILE *fp = popen(szAdpCtl, "r");
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (fp)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync char szBuf[VBOXNET_MAX_SHORT_NAME];
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (fgets(szBuf, sizeof(szBuf), fp))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync char *pLast = szBuf + strlen(szBuf) - 1;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (pLast >= szBuf && *pLast == '\n')
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync *pLast = 0;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync NETIFINFO Info;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync Bstr IfName(szBuf);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync rc = NetIfGetConfigByName(IfName, &Info);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (RT_FAILURE(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(),
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync "Failed to get config info for %s (as reported by '" VBOXNETADPCTL_NAME " add').\n", szBuf);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync /* create a new uninitialized host interface object */
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync ComObjPtr <HostNetworkInterface> iface;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync iface.createObject();
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync iface->init(IfName, HostNetworkInterfaceType_HostOnly, &Info);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync iface.queryInterfaceTo (aHostNetworkInterface);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if ((rc = pclose(fp)) != 0)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(), "Failed to execute '"VBOXNETADPCTL_NAME " add' (exit status: %d).", rc);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync rc = VERR_INTERNAL_ERROR;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (RT_SUCCESS(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress->notifyComplete(rc);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return rc;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_NOT_IMPLEMENTED;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#endif
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync /* create a progress object */
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync ComObjPtr <Progress> progress;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress.createObject();
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync ComPtr<IHost> host;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync int rc = VINF_SUCCESS;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync HRESULT hr = pVBox->COMGETTER(Host)(host.asOutParam());
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if(SUCCEEDED(hr))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync Bstr ifname;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync ComPtr <IHostNetworkInterface> iface;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (FAILED (host->FindHostNetworkInterfaceById (Guid(aId).toUtf16(), iface.asOutParam())))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_INVALID_PARAMETER;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync iface->COMGETTER (Name) (ifname.asOutParam());
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (ifname.isNull())
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_INTERNAL_ERROR;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync rc = progress->init (pVBox, host,
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync Bstr ("Removing host network interface"),
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync FALSE /* aCancelable */);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if(SUCCEEDED(rc))
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync CheckComRCReturnRC (rc);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress.queryInterfaceTo (aProgress);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync iface.queryInterfaceTo (aHostNetworkInterface);
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync rc = NetIfAdpCtl(Utf8Str(ifname), "remove", NULL, NULL);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync if (RT_FAILURE(rc))
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(), "Failed to execute '"VBOXNETADPCTL_NAME "' (exit status: %d).", rc);
cf9045d402be1e8b7344a439eaefe2ca4c2b53d3vboxsync else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress->notifyComplete(S_OK);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync {
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync progress->notifyComplete(hr);
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync rc = VERR_INTERNAL_ERROR;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync }
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return rc;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#else
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_NOT_IMPLEMENTED;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync#endif
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfGetConfig(HostNetworkInterface * /* pIf */, NETIFINFO *)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_NOT_IMPLEMENTED;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsyncint NetIfDhcpRediscover(VirtualBox * /* pVbox */, HostNetworkInterface * /* pIf */)
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync{
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync return VERR_NOT_IMPLEMENTED;
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync}
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync
1e7030f54deae0a8aa27817ab26c5d6d6c246541vboxsync