VBoxNetCfg.cpp revision f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * VBoxNetCfg.cpp - Network Configuration API.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Copyright (C) 2011 Oracle Corporation
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * available from http://www.virtualbox.org. This file is free software;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * General Public License (GPL) as published by the Free Software
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#ifndef Assert /** @todo r=bird: where would this be defined? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# ifdef DEBUG
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define Assert(_expr) assert(_expr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define Assert(_expr) do{ }while (0)
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#define DbgLog /** @todo r=bird: What does this do? */
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#define VBOX_NETCFG_LOCK_TIME_OUT 5000 /** @todo r=bird: What does this do? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinINetCfgLock(IN INetCfg *pNetCfg,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryInterface failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pLock->AcquireWriteLock(cmsTimeout, pszwClientDescription, ppszwClientDescription);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("AcquireWriteLock failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinINetCfgUnlock(IN INetCfg *pNetCfg)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryInterface failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("ReleaseWriteLock failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinQueryINetCfg(OUT INetCfg **ppNetCfg,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (PVOID*)&pNetCfg);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CoCreateInstance failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinINetCfgLock(pNetCfg, pszwClientDescription, cmsTimeout, ppszwClientDescription);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Initialize failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinReleaseINetCfg(IN INetCfg *pNetCfg, IN BOOL fHasWriteLock)
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Uninitialize failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinINetCfgUnlock failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic HRESULT vboxNetCfgWinGetComponentByGuidEnum(IEnumNetCfgComponent *pEnumNcc,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Reset failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while ((hr = pEnumNcc->Next(1, &pNcc, NULL)) == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* found the needed device */
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetInstanceGuid failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGetComponentByGuid(IN INetCfg *pNc,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNc->EnumComponents(pguidClass, &pEnumNcc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinGetComponentByGuidEnum(pEnumNcc, pComponentGuid, ppncc);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinGetComponentByGuidEnum failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("EnumComponents failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinQueryInstaller(IN INetCfg *pNetCfg, IN const GUID *pguidClass, INetCfgClassSetup **ppSetup)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->QueryNetCfgClass(pguidClass, IID_INetCfgClassSetup, (void**)ppSetup);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryNetCfgClass failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = vboxNetCfgWinQueryInstaller(pNetCfg, pguidClass, &pSetup);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinQueryInstaller failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync 0, /* IN DWORD dwSetupFlags */
d97357e2036109245c83ba553d0290212e28ea40vboxsync 0, /* IN DWORD dwUpgradeFromBuildNo */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* ignore the apply failure */
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Apply failed, hr (0x%x)\n", tmpHr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Install failed, hr (0x%x)\n", hr));
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync/** @todo r=bird: This function is not in the header file, why is it
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync * exported? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallInfAndComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Installing %u INF files ...\n", cInfPaths));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (; i < cInfPaths; i++)
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Installing INF file \"%ws\" ...\n", apInfPaths[i]));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("VBoxNetCfgWinInfInstall failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = VBoxNetCfgWinInstallComponent(pNetCfg, pszwComponentId, pguidClass, ppComponent);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("VBoxNetCfgWinInstallComponent failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinUninstallComponent(IN INetCfg *pNetCfg, IN INetCfgComponent *pComponent)
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetClassGuid failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinQueryInstaller(pNetCfg, &GuidClass, &pSetup);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinQueryInstaller failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSetup->DeInstall(pComponent, &Token, NULL /* OUT LPWSTR *pmszwRefs */);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Apply failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("DeInstall failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsynctypedef BOOL (*VBOXNETCFGWIN_NETCFGENUM_CALLBACK) (IN INetCfg *pNetCfg, IN INetCfgComponent *pNetCfgComponent, PVOID pContext);
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic HRESULT vboxNetCfgWinEnumNetCfgComponents(IN INetCfg *pNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = pNetCfg->EnumComponents(pguidClass, &pEnumComponent);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumComponent->Next(1, &pNetCfgComponent, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// ULONG uComponentStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// hr = pNcc->GetDeviceStatus(&uComponentStatus);
d97357e2036109245c83ba553d0290212e28ea40vboxsync// if (SUCCEEDED(hr))
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = callback(pNetCfg, pNetCfgComponent, pContext);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Next failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync } while (true);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic BOOL vboxNetCfgWinRemoveAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SetupDiSetClassInstallParams(hDevInfo,pDev,&rmdParams.ClassInstallHeader,sizeof(rmdParams)))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SetupDiCallClassInstaller(DIF_REMOVE,hDevInfo,pDev))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SetupDiGetDeviceInstallParams(hDevInfo,pDev,&devParams))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (devParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiCallClassInstaller failed with %ld\n", dwErr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetSelectedDevice failed with %ld\n", dwErr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetClassInstallParams failed with %ld\n", dwErr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef BOOL (*VBOXNETCFGWIN_NETENUM_CALLBACK) (HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnumNetDevices(LPCWSTR pPnPId, VBOXNETCFGWIN_NETENUM_CALLBACK callback, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (; bEnumCompleted = SetupDiEnumDeviceInfo(hDevInfo, iDev, &Dev); iDev++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo,&Dev,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetDeviceRegistryPropertyW (1) failed winErr(%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo,&Dev,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetDeviceRegistryPropertyW (2) failed winErr(%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = winEr == ERROR_NO_MORE_ITEMS ? S_OK : HRESULT_FROM_WIN32(winEr);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetClassDevsExW failed winErr(%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRemoveAllNetDevicesOfId(IN LPCWSTR lpszPnPId)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return VBoxNetCfgWinEnumNetDevices(lpszPnPId, vboxNetCfgWinRemoveAllNetDevicesOfIdCallback, NULL);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync LOG_ROUTINE pfnRoutine = (LOG_ROUTINE)(*((void * volatile *)&g_Logger));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync _vsnprintf(szBuffer, RT_ELEMENTS(szBuffer), szString, va);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(VOID) VBoxNetCfgWinSetLogging(IN LOG_ROUTINE pfnLog)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * IP configuration API
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* network settings config */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Strong referencing operators. Used as a second argument to ComPtr<>/ComObjPtr<>.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctemplate <class C>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Base template for smart COM pointers. Not intended to be used directly.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctemplate <class C, template <class> class RefOps = ComStrongRef>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* special template to disable AddRef()/Release() */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class I>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync class NoAddRefRelease : public I
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else /* !defined (VBOX_WITH_XPCOM) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif /* !defined (VBOX_WITH_XPCOM) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtrBase (const ComPtrBase &that) : p (that.p) { addref(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool isNull() const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return (p == NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool operator! () const { return isNull(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool operator< (C* that_p) const { return p < that_p; }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool operator== (C* that_p) const { return p == that_p; }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class I>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OC>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Intended to pass instances as in parameters to interface methods */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync operator C* () const { return p; }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Dereferences the instance (redirects the -> operator to the managed
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * pointer).
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NoAddRefRelease <C> *operator-> () const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync AssertMsg (p, ("Managed pointer must not be null\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return (NoAddRefRelease <C> *) p;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class I>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return p->QueryInterface (COM_IIDOF (I), (void **) pp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Intended to pass instances as out parameters to interface methods */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* be aware of self-assignment */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Smart COM pointer wrapper that automatically manages refcounting of
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * interface pointers.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * @param I COM interface class
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctemplate <class I, template <class> class RefOps = ComStrongRef>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OI>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr (OI *that_p) : Base () { operator= (that_p); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* specialization for I */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OC>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr (const ComPtr <OC, RefOps> &oc) : Base () { operator= ((OC *) oc); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OI>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync that_p->QueryInterface (COM_IIDOF (I), (void **) Base::asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* specialization for I */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OC>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, const GUID * pGuid, IWbemClassObject **pAdapterConfig)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync int length = StringFromGUID2(*pGuid, wszGuid, RT_ELEMENTS(wszGuid));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync swprintf(wszQuery, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", wszGuid);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(wszQuery), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("netIfWinFindAdapterClassById: IEnumWbemClassObject::Next -> hr=0x%x pclsObj=%p uReturn=%u 42=%u\n",
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("netIfWinFindAdapterClassById: S_OK and %p\n", *pAdapterConfig));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("ExecQuery returned no enumerator\n"));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("ExecQuery failed (0x%x)\n", hr));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("StringFromGUID2 failed winEr=%u, hr=0x%x\n", winEr, hr));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("netIfWinFindAdapterClassById: 0x%x and %p\n", hr, *pAdapterConfig));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinIsHostOnly(IWbemClassObject * pAdapterConfig, BOOL * pbIsHostOnly)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0 /*lFlags*/, &vtServiceName, NULL /*pvtType*/, NULL /*plFlavor*/);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync *pbIsHostOnly = bstr_t(vtServiceName.bstrVal) == bstr_t("VBoxNetAdp");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinGetIpSettings(IWbemClassObject * pAdapterConfig, ULONG *pIpv4, ULONG *pMaskv4)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPAddress", 0, &vtIp, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPSubnet", 0, &vtMask, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (LONG i = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayGetElement(pIpArray, &i, (PVOID)&pCurIp) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync && SafeArrayGetElement(pMaskArray, &i, (PVOID)&pCurMask) == S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinHasIpSettings(IWbemClassObject * pAdapterConfig, SAFEARRAY * pCheckIp, SAFEARRAY * pCheckMask, bool *pFound)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPAddress", 0, &vtIp, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPSubnet", 0, &vtMask, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (LONG k = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayGetElement(pCheckIp, &k, (PVOID)&pIp) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync && SafeArrayGetElement(pCheckMask, &k, (PVOID)&pMask) == S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (LONG i = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayGetElement(pIpArray, &i, (PVOID)&pCurIp) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync && SafeArrayGetElement(pMaskArray, &i, (PVOID)&pCurMask) == S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinWaitIpSettings(IWbemServices *pSvc, const GUID * pGuid, SAFEARRAY * pCheckIp, SAFEARRAY * pCheckMask, ULONG sec2Wait, bool *pFound)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* on Vista we need to wait for the address to get applied */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* wait for the address to appear in the list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (i = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync (hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam())) == S_OK
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync && (hr = netIfWinHasIpSettings(pAdapterConfig, pCheckIp, pCheckMask, pFound)) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIWbemServices(IWbemServices ** ppSvc)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pLoc->ConnectServer(bstr_t(L"ROOT\\CIMV2"), /* [in] const BSTR strNetworkResource */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0, /* [in] const BSTR strLocale */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0, /* [in] const BSTR strAuthority */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0, /* [in] IWbemContext* pCtx */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = CoSetProxyBlanket(pSvc, /* IUnknown * pProxy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RPC_C_IMP_LEVEL_IMPERSONATE, /* DWORD dwImpLevel */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* do not need it any more */
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CoSetProxyBlanket failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("ConnectServer failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CoCreateInstance failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinAdapterConfigPath(IWbemClassObject *pObj, BSTR * pStr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pStr = (bstr_t(L"Win32_NetworkAdapterConfiguration.Index='") + strIndex + "'").copy();
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Get failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfExecMethod(IWbemServices * pSvc, IWbemClassObject *pClass, BSTR ObjPath,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR MethodName, LPWSTR *pArgNames, LPVARIANT *pArgs, UINT cArgs,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pClass->GetMethod(MethodName, 0, pInParamsDefinition.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pInParamsDefinition->SpawnInstance(0, pClassInstance.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->ExecMethod(ObjPath, MethodName, 0, NULL, pClassInstance, &pOutParams, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArray(SAFEARRAY **ppArray, in_addr* aIp, UINT cIp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY * pIpArray = SafeArrayCreateVector(VT_BSTR, 0, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArrayV4V6(SAFEARRAY **ppArray, BSTR Ip)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY *pIpArray = SafeArrayCreateVector(VT_BSTR, 0, 1);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArrayVariantV4(VARIANT * pIpAddresses, in_addr* aIp, UINT cIp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArrayVariantV4V6(VARIANT * pIpAddresses, BSTR Ip)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableStatic(IWbemServices * pSvc, const GUID * pGuid, BSTR ObjPath, VARIANT * pIp, VARIANT * pMask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"EnableStatic"), argNames, args, 2, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// bool bFound;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// HRESULT tmpHr = netIfWinWaitIpSettings(pSvc, pGuid, pIp->parray, pMask->parray, 180, &bFound);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableStaticV4(IWbemServices * pSvc, const GUID * pGuid, BSTR ObjPath, in_addr* aIp, in_addr * aMask, UINT cIp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4(&ipAddresses, aIp, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIpArrayVariantV4(&ipMasks, aMask, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableStatic(pSvc, pGuid, ObjPath, &ipAddresses, &ipMasks);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableStaticV4V6(IWbemServices * pSvc, const GUID * pGuid, BSTR ObjPath, BSTR Ip, BSTR Mask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&ipAddresses, Ip);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIpArrayVariantV4V6(&ipMasks, Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableStatic(pSvc, pGuid, ObjPath, &ipAddresses, &ipMasks);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* win API allows to set gw metrics as well, we are not setting them */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinSetGateways(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pGw)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"SetGateways"), argNames, args, 1, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* win API allows to set gw metrics as well, we are not setting them */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinSetGatewaysV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aGw, UINT cGw)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4(&gwais, aGw, cGw);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* win API allows to set gw metrics as well, we are not setting them */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinSetGatewaysV4V6(IWbemServices * pSvc, BSTR ObjPath, BSTR Gw)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&vGw, Gw);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableDHCP(IWbemServices * pSvc, BSTR ObjPath)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"EnableDHCP"), NULL, NULL, 0, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinDhcpRediscover(IWbemServices * pSvc, BSTR ObjPath)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"ReleaseDHCPLease"), NULL, NULL, 0, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"RenewDHCPLease"), NULL, NULL, 0, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync // Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinIsDhcpEnabled(IWbemClassObject * pAdapterConfig, BOOL *pEnabled)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGetAdapterSettings(IN const GUID * pGuid, OUT PADAPTER_SETTINGS pSettings)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinIsDhcpEnabled(pAdapterConfig, &pSettings->bDhcp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinGetIpSettings(pAdapterConfig, &pSettings->ip, &pSettings->mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinIsDhcpEnabled(const GUID * pGuid, BOOL *pEnabled)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableStaticIpConfig(IN const GUID *pGuid, IN ULONG ip, IN ULONG mask)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: ip=0x%x mask=0x%x", ip, mask));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync HRESULT hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinEnableStaticV4(pSvc, pGuid, ObjPath, aIp, aMask, ip != 0 ? 1 : 0);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: returns 0x%x", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableStaticV4V6(pSvc, pAdapterConfig, ObjPath, aIPV6Address, aIPV6Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinSetGatewaysV4V6(pSvc, ObjPath, aIPV6DefaultGateway);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// hr = netIfWinUpdateConfig(pIf);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int rc = prefixLength2IPv6Address(aIPV6MaskPrefixLength, &Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rc = netIfEnableStaticIpConfigV6(pGuid, aIPV6Address, maskStr, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableDynamicIpConfig(IN const GUID *pGuid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// hr = netIfWinUpdateConfig(pIf);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinDhcpRediscover(IN const GUID *pGuid)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync //hr = netIfWinUpdateConfig(pIf);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef bool (*PFNVBOXNETCFG_IPSETTINGS_CALLBACK) (ULONG ip, ULONG mask, PVOID pContext);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic void vboxNetCfgWinEnumIpConfig(PIP_ADAPTER_ADDRESSES pAddresses, PFNVBOXNETCFG_IPSETTINGS_CALLBACK pfnCallback, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (pAdapter = pAddresses; pAdapter; pAdapter = pAdapter->Next)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_UNICAST_ADDRESS pAddr = pAdapter->FirstUnicastAddress;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_PREFIX pPrefix = pAdapter->FirstPrefix;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &((struct sockaddr_in *)pAddr->Address.lpSockaddr)->sin_addr.s_addr,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// case AF_INET6:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (; pPrefix && !fMaskFound; pPrefix = pPrefix->Next)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!pPrefix->PrefixLength || pPrefix->PrefixLength > 31) /* in case the ip helper API is queried while NetCfg write lock is held */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break; /* the address values can contain illegal values */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// case AF_INET6:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync } while (true);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic bool vboxNetCfgWinIpProbeCallback (ULONG ip, ULONG mask, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIPPROBE_CONTEXT pProbe = (PIPPROBE_CONTEXT)pContext;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return false;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(OUT PULONG pNetIp, OUT PULONG pNetMask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Most of the hosts probably have less than 10 adapters,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * so we'll mostly succeed from the first attempt.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Impressive! More than 10 adapters! Get more memory and try again. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (int i = 0; i < 255; i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync vboxNetCfgWinEnumIpConfig(pAddresses, vboxNetCfgWinIpProbeCallback, &Context);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetAdaptersAddresses err (%d)\n", dwRc));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * convenience functions to perform netflt/adp manipulations
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETCFGWIN_NETFLT_MP_ID L"sun_VBoxNetFltmp"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinNetFltUninstall(IN INetCfg *pNc, DWORD InfRmFlags)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNc->FindComponent(VBOXNETCFGWIN_NETFLT_ID, &pNcc);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLog("NetFlt is installed currently, uninstalling ...\n");
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLog("NetFlt is not installed currently\n");
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("FindComponent failed, hr (0x%x)\n", hr));
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync VBoxDrvCfgInfUninstallAllF(L"NetService", VBOXNETCFGWIN_NETFLT_ID, InfRmFlags);
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync VBoxDrvCfgInfUninstallAllF(L"Net", VBOXNETCFGWIN_NETFLT_MP_ID, InfRmFlags);
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltUninstall(IN INetCfg *pNc)
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltInstall(IN INetCfg *pNc,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync IN LPCWSTR const *apInfFullPaths, IN UINT cInfFullPaths)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = vboxNetCfgWinNetFltUninstall(pNc, SUOI_FORCEDELETE);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = VBoxNetCfgWinInstallInfAndComponent(pNc, VBOXNETCFGWIN_NETFLT_ID,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOX_CONNECTION_NAME L"VirtualBox Host-Only Network"
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName(PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf)
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic BOOL vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority(IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Get component's binding. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = pNcc->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pNetCfgBindings);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Get binding path enumerator reference. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindings->EnumBindingPaths(EBP_BELOW, &pEnumNetCfgBindPath);
d97357e2036109245c83ba553d0290212e28ea40vboxsync bool bFoundIface = false;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumNetCfgBindPath->Next(1, &pNetCfgBindPath, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindPath->EnumBindingInterfaces(&pEnumNetCfgBindIface);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumNetCfgBindIface->Next(1, &pNetCfgBindIfce, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindIfce->GetLowerComponent(&pNetCfgCompo);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgCompo->GetDeviceStatus(&uComponentStatus);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindings->MoveAfter(pNetCfgBindPath, NULL);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Unable to move interface, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetLowerComponent failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr == S_FALSE) /* No more binding interfaces? */
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Next binding interface failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("EnumBindingInterfaces failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Next bind path failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("EnumBindingPaths failed, hr (0x%x)\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryInterface for IID_INetCfgComponentBindings failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return SetupDefaultQueueCallback(Context, Notification, Param1, Param2);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* The original source of the VBoxNetAdp adapter creation/destruction code has the following copyright */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Copyright 2004 by the Massachusetts Institute of Technology
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync All rights reserved.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Permission to use, copy, modify, and distribute this software and its
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync documentation for any purpose and without fee is hereby granted,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync provided that the above copyright notice appear in all copies and that
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync both that copyright notice and this permission notice appear in
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync supporting documentation, and that the name of the Massachusetts
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Institute of Technology (M.I.T.) not be used in advertising or publicity
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pertaining to distribution of the software without specific, written
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync prior permission.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Use the IShellFolder API to rename the connection.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT rename_shellfolder (PCWSTR wGuid, PCWSTR wNewName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* This is the GUID for the network connections folder. It is constant.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * {7007ACC7-3202-11D1-AAD2-00805FC1270E} */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Build the display name in the form "::{GUID}". */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Create an instance of the network connections folder. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Parse the display name. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pShellFolder->ParseDisplayName (NULL, NULL, szAdapterGuid, NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pShellFolder->SetNameOf (NULL, pidl, wNewName, SHGDN_NORMAL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync typedef HRESULT (WINAPI *lpHrRenameConnection) (const GUID *, PCWSTR);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* First try the IShellFolder interface, which was unimplemented
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * for the network connections folder before XP. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** @todo that code doesn't seem to work! */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* The IShellFolder interface is not implemented on this platform.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Try the (undocumented) HrRenameConnection API in the netshell
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * library. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = CLSIDFromString ((LPOLESTR) pGuid, &clsid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync "HrRenameConnection");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync } else do {} while (0)
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRemoveHostOnlyNetworkInterface(IN const GUID *pGUID, OUT BSTR *pErrMsg)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* We have to find the device instance ID through a registry search */
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync int length = StringFromGUID2(*pGUID, wszGuid, RT_ELEMENTS(wszGuid));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync L"SYSTEM\\CurrentControlSet\\Control\\Network\\"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync L"{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RegOpenKeyExW (HKEY_LOCAL_MACHINE, strRegLocation, 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host interface network is not found in registry (%S) [1]",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RegOpenKeyExW (hkeyNetwork, L"Connection", 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host interface network is not found in registry (%S) [2]",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RegQueryValueExW (hkeyConnection, L"PnPInstanceID", NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if ((status != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host interface network is not found in registry (%S) [3]",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Now we are going to enumerate all network devices and
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * wait until we encounter the right device instance ID
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* initialize the structure size */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* copy the net class GUID */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy (&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* return a device info set contains all installed devices of the Net class */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hDeviceInfo = SetupDiGetClassDevs (&netGuid, NULL, NULL, DIGCF_PRESENT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiGetClassDevs failed (0x%08X)", GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* enumerate the driver info list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiEnumDeviceInfo (hDeviceInfo, index, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* try to get the hardware ID registry property */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* something is wrong. This shouldn't have worked with a NULL buffer */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device instance ID */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* compare to what we determined before */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host Interface Network driver not found (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiCallClassInstaller (DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* clean up the device info set */
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* for our purposes, 2k buffer is more
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * than enough to obtain the hardware ID
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * of the VBoxNetAdp driver. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* initialize the structure size */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* copy the net class GUID */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof(GUID_DEVCLASS_NET));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* create an empty device info set associated with the net class GUID */
d97357e2036109245c83ba553d0290212e28ea40vboxsync hDeviceInfo = SetupDiCreateDeviceInfoList(&netGuid, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCreateDeviceInfoList failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the class name from GUID */
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL fResult = SetupDiClassNameFromGuid (&netGuid, className, MAX_PATH, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiClassNameFromGuid failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* create a device info element and add the new device instance
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * key to registry */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCreateDeviceInfo (hDeviceInfo, className, &netGuid, NULL, NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCreateDeviceInfo failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* select the newly created device info to be the currently
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync selected member */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device install parameters and disable filecopy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memset(DeviceInstallParams.DriverPath, 0, sizeof(DeviceInstallParams.DriverPath));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync size_t pathLenght = wcslen(pInfPath) + 1/* null terminator */;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pathLenght < sizeof(DeviceInstallParams.DriverPath)/sizeof(DeviceInstallParams.DriverPath[0]))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy(DeviceInstallParams.DriverPath, pInfPath, pathLenght*sizeof(DeviceInstallParams.DriverPath[0]));
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetDeviceInstallParams faileed: INF path is too long\n"));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* build a list of class drivers */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiBuildDriverInfoList (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiBuildDriverInfoList failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* enumerate the driver info list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ret = SetupDiEnumDriverInfo (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* if the function failed and GetLastError() returned
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * ERROR_NO_MORE_ITEMS, then we have reached the end of the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * list. Otherwise there was something wrong with this
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * particular driver. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pDriverInfoDetail = (PSP_DRVINFO_DETAIL_DATA) detailBuf;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pDriverInfoDetail->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* if we successfully find the hardware ID and it turns out to
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * be the one for the loopback driver, then we are done. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* pDriverInfoDetail->HardwareID is a MULTISZ string. Go through the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * whole list and see if there is a match somewhere. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (t && *t && t < (TCHAR *) &detailBuf [RT_ELEMENTS(detailBuf)])
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (t && *t && t < (TCHAR *) &detailBuf [RT_ELEMENTS(detailBuf)])
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetErrBreak(("Could not find Host Interface Networking driver! Please reinstall"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* set the loopback driver to be the currently selected */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetSelectedDriver (hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetErrBreak(("SetupDiSetSelectedDriver failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* register the phantom device to prepare for install */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller (DIF_REGISTERDEVICE, hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* registered, but remove if errors occur in the following code */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* ask the installer if we can install the device */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller (DIF_ALLOW_INSTALL, hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_ALLOW_INSTALL) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* that's fine */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device install parameters and disable filecopy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pQueueCallbackContext = SetupInitDefaultQueueCallback(NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.InstallMsgHandlerContext = pQueueCallbackContext;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.InstallMsgHandler = (PSP_FILE_CALLBACK)vboxNetCfgWinPspFileCallback;
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupInitDefaultQueueCallback failed, winEr (%d)\n", winEr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* install the files first */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES, hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device install parameters and disable filecopy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiSetDeviceInstallParams failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Register any device-specific co-installers for this device,
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_REGISTER_COINSTALLERS) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * install any installer-specified interfaces.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * and then do the real install
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_INSTALLINTERFACES,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLINTERFACES) failed (0x%08X)",
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_INSTALLDEVICE,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICE) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Figure out NetCfgInstanceId */
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync SetErrBreak(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiGetDeviceRegistryProperty failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiGetDeviceRegistryProperty failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetupTermDefaultQueueCallback(pQueueCallbackContext);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* an error has occurred, but the device is registered, we must remove it */
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync found = SetupDiDeleteDeviceInfo(hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* destroy the driver info list */
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupDiDestroyDriverInfoList(hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* clean up the device info set */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* return the network connection GUID on success */
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(DevName, ConnectoinName, &cbName);
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = VBoxNetCfgWinRenameConnection(pWCfgGuidString, ConnectoinName);
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync *lppszName = SysAllocString((const OLECHAR *) DevName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc));
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation",
d97357e2036109245c83ba553d0290212e28ea40vboxsync 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* TODO: special handling for 6to4svc.dll ???, i.e. several retrieves */
d97357e2036109245c83ba553d0290212e28ea40vboxsync vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
d97357e2036109245c83ba553d0290212e28ea40vboxsync vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
d97357e2036109245c83ba553d0290212e28ea40vboxsync vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp));
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr));