Changeset 17358 in vbox
- Timestamp:
- Mar 4, 2009 5:42:18 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostNetworkInterfaceImpl.cpp
r17337 r17358 105 105 } 106 106 107 /** 108 * Initializes the host object. 109 * 110 * @returns COM result indicator 111 * @param aInterfaceName name of the network interface 112 * @param aGuid GUID of the host network interface 113 */ 114 HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf) 115 { 116 // LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n", 117 // aInterfaceName.raw(), aGuid.toString().raw())); 118 119 // ComAssertRet (aInterfaceName, E_INVALIDARG); 120 // ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG); 121 ComAssertRet (pIf, E_INVALIDARG); 122 123 /* Enclose the state transition NotReady->InInit->Ready */ 124 AutoInitSpan autoInitSpan (this); 125 AssertReturn (autoInitSpan.isOk(), E_FAIL); 126 127 unconst (mInterfaceName) = aInterfaceName; 128 unconst (mGuid) = pIf->Uuid; 129 mIfType = ifType; 130 107 HRESULT HostNetworkInterface::updateConfig (struct NETIFINFO *pIf) 108 { 131 109 m.IPAddress = pIf->IPAddress.u; 132 110 m.networkMask = pIf->IPNetMask.u; … … 134 112 m.IPV6Address = composeIPv6Address(&pIf->IPv6Address); 135 113 m.IPV6NetworkMask = composeIPv6Address(&pIf->IPv6NetMask); 114 m.IPV6DefaultGateway = composeIPv6Address(&pIf->IPV6DefaultGateway); 136 115 m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress); 137 116 #ifdef RT_OS_WINDOWS … … 143 122 #endif /* !RT_OS_WINDOWS */ 144 123 124 return S_OK; 125 } 126 127 /** 128 * Initializes the host object. 129 * 130 * @returns COM result indicator 131 * @param aInterfaceName name of the network interface 132 * @param aGuid GUID of the host network interface 133 */ 134 HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf) 135 { 136 // LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n", 137 // aInterfaceName.raw(), aGuid.toString().raw())); 138 139 // ComAssertRet (aInterfaceName, E_INVALIDARG); 140 // ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG); 141 ComAssertRet (pIf, E_INVALIDARG); 142 143 /* Enclose the state transition NotReady->InInit->Ready */ 144 AutoInitSpan autoInitSpan (this); 145 AssertReturn (autoInitSpan.isOk(), E_FAIL); 146 147 unconst (mInterfaceName) = aInterfaceName; 148 unconst (mGuid) = pIf->Uuid; 149 mIfType = ifType; 150 151 updateConfig(pIf); 152 145 153 /* Confirm a successful initialization */ 146 154 autoInitSpan.setSucceeded(); … … 244 252 } 245 253 254 STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Supported) (BOOL *aIPV6Supported) 255 { 256 CheckComArgOutPointerValid(aIPV6Supported); 257 258 *aIPV6Supported = TRUE; 259 260 return S_OK; 261 } 262 246 263 /** 247 264 * Returns the IP V6 address of the host network interface. … … 281 298 282 299 /** 300 * Returns the IP V6 default gateway of the host network interface. 301 * 302 * @returns COM status code 303 * @param aIPV6DefaultGateway address of result pointer 304 */ 305 STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6DefaultGateway) (BSTR *aIPV6DefaultGateway) 306 { 307 CheckComArgOutPointerValid(aIPV6DefaultGateway); 308 309 AutoCaller autoCaller (this); 310 CheckComRCReturnRC (autoCaller.rc()); 311 312 m.IPV6DefaultGateway.cloneTo (aIPV6DefaultGateway); 313 314 return S_OK; 315 } 316 317 /** 283 318 * Returns the hardware address of the host network interface. 284 319 * … … 355 390 STDMETHODIMP HostNetworkInterface::EnableStaticIpConfig (ULONG aIPAddress, ULONG aNetworkMask, ULONG aDefaultGateway) 356 391 { 392 #ifndef VBOX_WITH_HOSTNETIF_API 357 393 return E_NOTIMPL; 358 } 359 360 STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask) 361 { 394 #else 395 AutoCaller autoCaller (this); 396 CheckComRCReturnRC (autoCaller.rc()); 397 398 int rc = NetIfEnableStaticIpConfig(this, aIPAddress, aNetworkMask, aDefaultGateway); 399 if (RT_FAILURE(rc)) 400 { 401 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc)); 402 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL; 403 } 404 return S_OK; 405 #endif 406 } 407 408 STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway) 409 { 410 #ifndef VBOX_WITH_HOSTNETIF_API 362 411 return E_NOTIMPL; 412 #else 413 if (!aIPV6Address) 414 return E_INVALIDARG; 415 if (!aIPV6DefaultGateway) 416 return E_INVALIDARG; 417 if (aIPV6MaskPrefixLength > 128) 418 return E_INVALIDARG; 419 420 AutoCaller autoCaller (this); 421 CheckComRCReturnRC (autoCaller.rc()); 422 423 int rc = NetIfEnableStaticIpConfigV6(this, aIPV6Address, aIPV6MaskPrefixLength, aIPV6DefaultGateway); 424 if (RT_FAILURE(rc)) 425 { 426 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc)); 427 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL; 428 } 429 return S_OK; 430 #endif 363 431 } 364 432 365 433 STDMETHODIMP HostNetworkInterface::EnableDynamicIpConfig () 366 434 { 435 #ifndef VBOX_WITH_HOSTNETIF_API 367 436 return E_NOTIMPL; 437 #else 438 AutoCaller autoCaller (this); 439 CheckComRCReturnRC (autoCaller.rc()); 440 441 int rc = NetIfEnableDynamicIpConfig(this); 442 if (RT_FAILURE(rc)) 443 { 444 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc)); 445 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL; 446 } 447 return S_OK; 448 #endif 368 449 } 369 450 -
trunk/src/VBox/Main/darwin/NetIfList-darwin.cpp
r17275 r17358 140 140 return VINF_SUCCESS; 141 141 } 142 143 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask, ULONG gw) 144 { 145 return VERR_NOT_IMPLEMENTED; 146 } 147 148 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway) 149 { 150 return VERR_NOT_IMPLEMENTED; 151 } 152 153 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf) 154 { 155 return VERR_NOT_IMPLEMENTED; 156 } -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r17336 r17358 6438 6438 <enum 6439 6439 name="HostNetworkInterfaceType" 6440 uuid=" 4cd97025-b31b-430b-98dd-211e85cf389f"6440 uuid="67431b00-9946-48a2-bc02-b25c5919f4f3" 6441 6441 > 6442 6442 <desc> … … 6478 6478 </attribute> 6479 6479 6480 <attribute name="IPV6Supported" type="boolean" readonly="yes"> 6481 <desc>Specifies whether the IP V6 is supported/enabled for the interface.</desc> 6482 </attribute> 6483 6480 6484 <attribute name="IPV6Address" type="wstring" readonly="yes"> 6481 6485 <desc>Returns the IP V6 address of the interface.</desc> … … 6486 6490 </attribute> 6487 6491 6492 <attribute name="IPV6DefaultGateway" type="wstring" readonly="yes"> 6493 <desc>Returns the IP V6 network mask of the interface.</desc> 6494 </attribute> 6495 6488 6496 <attribute name="hardwareAddress" type="wstring" readonly="yes"> 6489 6497 <desc>Returns the hardware address. For Ethernet it is MAC address.</desc> … … 6528 6536 </desc> 6529 6537 </param> 6530 <param name="IPV6NetworkMask" type="wstring" dir="in"> 6538 <param name="IPV6NetworkMaskPrefixLength" type="unsigned long" dir="in"> 6539 <desc> 6540 network mask. 6541 </desc> 6542 </param> 6543 <param name="IPV6DefaultGateway" type="wstring" dir="in"> 6531 6544 <desc> 6532 6545 network mask. -
trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h
r17337 r17358 63 63 #ifdef VBOX_WITH_HOSTNETIF_API 64 64 HRESULT init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, struct NETIFINFO *pIfs); 65 HRESULT updateConfig (struct NETIFINFO *pIfs); 65 66 #endif 66 67 … … 71 72 STDMETHOD(COMGETTER(NetworkMask)) (ULONG *aNetworkMask); 72 73 STDMETHOD(COMGETTER(DefaultGateway)) (ULONG *aDefaultGateway); 74 STDMETHOD(COMGETTER(IPV6Supported)) (BOOL *aIPV6Supported); 73 75 STDMETHOD(COMGETTER(IPV6Address)) (BSTR *aIPV6Address); 74 76 STDMETHOD(COMGETTER(IPV6NetworkMask)) (BSTR *aIPV6Mask); 77 STDMETHOD(COMGETTER(IPV6DefaultGateway)) (BSTR *aDefaultGateway); 75 78 STDMETHOD(COMGETTER(HardwareAddress)) (BSTR *aHardwareAddress); 76 79 STDMETHOD(COMGETTER(MediumType)) (HostNetworkInterfaceMediumType_T *aType); … … 79 82 80 83 STDMETHOD(EnableStaticIpConfig) (ULONG aIPAddress, ULONG aNetworkMask, ULONG aDefaultGateway); 81 STDMETHOD(EnableStaticIpConfigV6) (IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask);84 STDMETHOD(EnableStaticIpConfigV6) (IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway); 82 85 STDMETHOD(EnableDynamicIpConfig) (); 83 86 … … 101 104 Bstr IPV6Address; 102 105 Bstr IPV6NetworkMask; 106 Bstr IPV6DefaultGateway; 103 107 Bstr hardwareAddress; 104 108 HostNetworkInterfaceMediumType_T mediumType; -
trunk/src/VBox/Main/include/netif.h
r17309 r17358 62 62 RTNETADDRIPV6 IPv6Address; 63 63 RTNETADDRIPV6 IPv6NetMask; 64 RTNETADDRIPV6 IPV6DefaultGateway; 64 65 RTMAC MACAddress; 65 66 NETIFTYPE enmMediumType; … … 77 78 78 79 int NetIfList(std::list <ComObjPtr <HostNetworkInterface> > &list); 80 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask, ULONG gw); 81 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway); 82 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf); 79 83 80 84 #endif -
trunk/src/VBox/Main/linux/NetIfList-linux.cpp
r17275 r17358 159 159 } 160 160 161 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask, ULONG gw) 162 { 163 return VERR_NOT_IMPLEMENTED; 164 } 161 165 166 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway) 167 { 168 return VERR_NOT_IMPLEMENTED; 169 } 170 171 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf) 172 { 173 return VERR_NOT_IMPLEMENTED; 174 } -
trunk/src/VBox/Main/os2/NetIfList-os2.cpp
r15548 r17358 37 37 return VERR_NOT_IMPLEMENTED; 38 38 } 39 40 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask, ULONG gw) 41 { 42 return VERR_NOT_IMPLEMENTED; 43 } 44 45 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway) 46 { 47 return VERR_NOT_IMPLEMENTED; 48 } 49 50 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf) 51 { 52 return VERR_NOT_IMPLEMENTED; 53 } 54 -
trunk/src/VBox/Main/solaris/NetIfList-solaris.cpp
r17275 r17358 382 382 } 383 383 #endif 384 385 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask, ULONG gw) 386 { 387 return VERR_NOT_IMPLEMENTED; 388 } 389 390 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway) 391 { 392 return VERR_NOT_IMPLEMENTED; 393 } 394 395 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf) 396 { 397 return VERR_NOT_IMPLEMENTED; 398 } -
trunk/src/VBox/Main/win/NetIfList-win.cpp
r17337 r17358 195 195 } 196 196 197 static HRESULT netIf AdapterConfigPath(IWbemClassObject *pObj, BSTR * pStr)197 static HRESULT netIfWinAdapterConfigPath(IWbemClassObject *pObj, BSTR * pStr) 198 198 { 199 199 VARIANT index; … … 266 266 } 267 267 268 static HRESULT createIpArray(SAFEARRAY **ppArray, in_addr* aIp, UINT cIp)268 static HRESULT netIfWinCreateIpArray(SAFEARRAY **ppArray, in_addr* aIp, UINT cIp) 269 269 { 270 270 HRESULT hr; … … 302 302 } 303 303 304 static HRESULT VBoxNetCfgWinEnableStatic(IWbemServices * pSvc, IWbemClassObject *pObj, in_addr* aIp, in_addr * aMask, UINT cIp) 305 { 306 IWbemClassObject * pClass; 304 static HRESULT netIfWinCreateIpArrayV4V6(SAFEARRAY **ppArray, BSTR Ip) 305 { 306 HRESULT hr; 307 SAFEARRAY * pIpArray = SafeArrayCreateVector(VT_BSTR, 0, 1); 308 if(pIpArray) 309 { 310 BSTR val = bstr_t(Ip, false).copy(); 311 long aIndex[1]; 312 aIndex[0] = 0; 313 hr = SafeArrayPutElement(pIpArray, aIndex, val); 314 if(FAILED(hr)) 315 { 316 SysFreeString(val); 317 SafeArrayDestroy(pIpArray); 318 } 319 320 if(SUCCEEDED(hr)) 321 { 322 *ppArray = pIpArray; 323 } 324 } 325 else 326 { 327 DWORD dwError = GetLastError(); 328 Assert(0); 329 hr = HRESULT_FROM_WIN32( dwError ); 330 } 331 332 return hr; 333 } 334 335 336 static HRESULT netIfWinCreateIpArrayVariantV4(VARIANT * pIpAddresses, in_addr* aIp, UINT cIp) 337 { 338 HRESULT hr; 339 VariantInit(pIpAddresses); 340 pIpAddresses->vt = VT_ARRAY | VT_BSTR; 341 SAFEARRAY *pIpArray; 342 hr = netIfWinCreateIpArray(&pIpArray, aIp, cIp); 343 if(SUCCEEDED(hr)) 344 { 345 pIpAddresses->parray = pIpArray; 346 } 347 return hr; 348 } 349 350 static HRESULT netIfWinCreateIpArrayVariantV4V6(VARIANT * pIpAddresses, BSTR Ip) 351 { 352 HRESULT hr; 353 VariantInit(pIpAddresses); 354 pIpAddresses->vt = VT_ARRAY | VT_BSTR; 355 SAFEARRAY *pIpArray; 356 hr = netIfWinCreateIpArrayV4V6(&pIpArray, Ip); 357 if(SUCCEEDED(hr)) 358 { 359 pIpAddresses->parray = pIpArray; 360 } 361 return hr; 362 } 363 364 static HRESULT netIfWinEnableStatic(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pIp, VARIANT * pMask) 365 { 366 ComPtr<IWbemClassObject> pClass; 307 367 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration"); 308 368 HRESULT hr; 309 369 if(ClassName) 310 370 { 311 hr = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);371 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL); 312 372 if(SUCCEEDED(hr)) 313 373 { 314 BSTR ObjPath; 315 hr = netIfAdapterConfigPath(pObj, &ObjPath); 374 LPWSTR argNames[] = {L"IPAddress", L"SubnetMask"}; 375 LPVARIANT args[] = {pIp, pMask}; 376 ComPtr<IWbemClassObject> pOutParams; 377 378 hr = netIfExecMethod(pSvc, pClass, ObjPath, 379 bstr_t(L"EnableStatic"), argNames, args, 2, pOutParams.asOutParam()); 316 380 if(SUCCEEDED(hr)) 317 381 { 318 LPWSTR argNames[] = {L"IPAddress", L"SubnetMask"}; 319 VARIANT ipAddresses; 320 VariantInit(&ipAddresses); 321 ipAddresses.vt = VT_ARRAY | VT_BSTR; 322 SAFEARRAY *pIpArray; 323 hr = createIpArray(&pIpArray, aIp, cIp); 324 if(SUCCEEDED(hr)) 325 { 326 ipAddresses.parray = pIpArray; 327 VARIANT ipMasks; 328 VariantInit(&ipMasks); 329 ipMasks.vt = VT_ARRAY | VT_BSTR; 330 SAFEARRAY *pMaskArray; 331 hr = createIpArray(&pMaskArray, aMask, cIp); 332 if(SUCCEEDED(hr)) 333 { 334 ipMasks.parray = pMaskArray; 335 LPVARIANT args[] = {&ipAddresses, &ipMasks}; 336 IWbemClassObject * pOutParams; 337 338 hr = netIfExecMethod(pSvc, pClass, ObjPath, 339 bstr_t(L"EnableStatic"), argNames, args, 2, &pOutParams); 340 if(SUCCEEDED(hr)) 341 { 342 } 343 SafeArrayDestroy(pMaskArray); 344 } 345 SafeArrayDestroy(pIpArray); 346 } 347 SysFreeString(ObjPath); 348 } 349 pClass->Release(); 382 } 350 383 } 351 384 SysFreeString(ClassName); … … 361 394 } 362 395 363 static HRESULT VBoxNetCfgWinEnableDHCP(IWbemServices * pSvc, IWbemClassObject *pObj, in_addr* aIp, in_addr * aMask, UINT cIp) 364 { 365 IWbemClassObject * pClass; 396 397 static HRESULT netIfWinEnableStaticV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aIp, in_addr * aMask, UINT cIp) 398 { 399 VARIANT ipAddresses; 400 HRESULT hr = netIfWinCreateIpArrayVariantV4(&ipAddresses, aIp, cIp); 401 if(SUCCEEDED(hr)) 402 { 403 VARIANT ipMasks; 404 hr = netIfWinCreateIpArrayVariantV4(&ipMasks, aMask, cIp); 405 if(SUCCEEDED(hr)) 406 { 407 netIfWinEnableStatic(pSvc, ObjPath, &ipAddresses, &ipMasks); 408 VariantClear(&ipMasks); 409 } 410 VariantClear(&ipAddresses); 411 } 412 return hr; 413 } 414 415 static HRESULT netIfWinEnableStaticV4V6(IWbemServices * pSvc, BSTR ObjPath, BSTR Ip, BSTR Mask) 416 { 417 VARIANT ipAddresses; 418 HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&ipAddresses, Ip); 419 if(SUCCEEDED(hr)) 420 { 421 VARIANT ipMasks; 422 hr = netIfWinCreateIpArrayVariantV4V6(&ipMasks, Mask); 423 if(SUCCEEDED(hr)) 424 { 425 netIfWinEnableStatic(pSvc, ObjPath, &ipAddresses, &ipMasks); 426 VariantClear(&ipMasks); 427 } 428 VariantClear(&ipAddresses); 429 } 430 return hr; 431 } 432 433 /* win API allows to set gw metrics as well, we are not setting them */ 434 static HRESULT netIfWinSetGateways(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pGw) 435 { 436 ComPtr<IWbemClassObject> pClass; 366 437 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration"); 367 438 HRESULT hr; 368 439 if(ClassName) 369 440 { 370 hr = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);441 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL); 371 442 if(SUCCEEDED(hr)) 372 443 { 373 BSTR ObjPath; 374 hr = netIfAdapterConfigPath(pObj, &ObjPath); 444 LPWSTR argNames[] = {L"DefaultIPGateway"}; 445 LPVARIANT args[] = {pGw}; 446 ComPtr<IWbemClassObject> pOutParams; 447 448 hr = netIfExecMethod(pSvc, pClass, ObjPath, 449 bstr_t(L"SetGateways"), argNames, args, 1, pOutParams.asOutParam()); 375 450 if(SUCCEEDED(hr)) 376 451 { 377 IWbemClassObject * pOutParams; 378 379 hr = netIfExecMethod(pSvc, pClass, ObjPath, 380 bstr_t(L"EnableDHCP"), NULL, NULL, 0, &pOutParams); 381 if(SUCCEEDED(hr)) 382 { 383 } 384 SysFreeString(ObjPath); 385 } 386 pClass->Release(); 452 } 453 } 454 SysFreeString(ClassName); 455 } 456 else 457 { 458 DWORD dwError = GetLastError(); 459 Assert(0); 460 hr = HRESULT_FROM_WIN32( dwError ); 461 } 462 463 return hr; 464 } 465 466 /* win API allows to set gw metrics as well, we are not setting them */ 467 static HRESULT netIfWinSetGatewaysV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aGw, UINT cGw) 468 { 469 VARIANT gwais; 470 HRESULT hr = netIfWinCreateIpArrayVariantV4(&gwais, aGw, cGw); 471 if(SUCCEEDED(hr)) 472 { 473 netIfWinSetGateways(pSvc, ObjPath, &gwais); 474 VariantClear(&gwais); 475 } 476 return hr; 477 } 478 479 /* win API allows to set gw metrics as well, we are not setting them */ 480 static HRESULT netIfWinSetGatewaysV4V6(IWbemServices * pSvc, BSTR ObjPath, BSTR Gw) 481 { 482 VARIANT vGw; 483 HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&vGw, Gw); 484 if(SUCCEEDED(hr)) 485 { 486 netIfWinSetGateways(pSvc, ObjPath, &vGw); 487 VariantClear(&vGw); 488 } 489 return hr; 490 } 491 492 static HRESULT netIfWinEnableDHCP(IWbemServices * pSvc, BSTR ObjPath) 493 { 494 ComPtr<IWbemClassObject> pClass; 495 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration"); 496 HRESULT hr; 497 if(ClassName) 498 { 499 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL); 500 if(SUCCEEDED(hr)) 501 { 502 ComPtr<IWbemClassObject> pOutParams; 503 504 hr = netIfExecMethod(pSvc, pClass, ObjPath, 505 bstr_t(L"EnableDHCP"), NULL, NULL, 0, pOutParams.asOutParam()); 506 if(SUCCEEDED(hr)) 507 { 508 } 387 509 } 388 510 SysFreeString(ClassName); … … 498 620 } 499 621 622 static HRESULT netIfWinUpdateConfig(HostNetworkInterface * pIf) 623 { 624 NETIFINFO Info; 625 memset(&Info, 0, sizeof(Info)); 626 GUID guid; 627 HRESULT hr = pIf->COMGETTER(Id) (&guid); 628 if(SUCCEEDED(hr)) 629 { 630 Info.Uuid = (RTUUID)*(RTUUID*)&guid; 631 BSTR name; 632 hr = pIf->COMGETTER(Name) (&name); 633 Assert(hr == S_OK); 634 if(hr == S_OK) 635 { 636 int rc = collectNetIfInfo(Bstr(name), &Info); 637 if (RT_SUCCESS(rc)) 638 { 639 hr = pIf->updateConfig(&Info); 640 } 641 else 642 { 643 Log(("netIfWinUpdateConfig: collectNetIfInfo() -> %Vrc\n", rc)); 644 hr = E_FAIL; 645 } 646 } 647 } 648 649 return hr; 650 } 651 652 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask, ULONG gw) 653 { 654 HRESULT hr; 655 GUID guid; 656 hr = pIf->COMGETTER(Id) (&guid); 657 if(SUCCEEDED(hr)) 658 { 659 ComPtr <IWbemServices> pSvc; 660 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 661 if(SUCCEEDED(hr)) 662 { 663 ComPtr <IWbemClassObject> pAdapterConfig; 664 hr = netIfWinFindAdapterClassById(pSvc, &guid, pAdapterConfig.asOutParam()); 665 if(SUCCEEDED(hr)) 666 { 667 in_addr aIp[1]; 668 in_addr aMask[1]; 669 aIp[0].S_un.S_addr = ip; 670 aMask[0].S_un.S_addr = mask; 671 672 BSTR ObjPath; 673 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 674 if(SUCCEEDED(hr)) 675 { 676 hr = netIfWinEnableStaticV4(pSvc, ObjPath, aIp, aMask, 1); 677 if(SUCCEEDED(hr)) 678 { 679 in_addr aGw[1]; 680 aGw[0].S_un.S_addr = gw; 681 hr = netIfWinSetGatewaysV4(pSvc, ObjPath, aGw, 1); 682 if(SUCCEEDED(hr)) 683 { 684 hr = netIfWinUpdateConfig(pIf); 685 } 686 } 687 SysFreeString(ObjPath); 688 } 689 } 690 } 691 } 692 693 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 694 } 695 696 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway) 697 { 698 HRESULT hr; 699 GUID guid; 700 hr = pIf->COMGETTER(Id) (&guid); 701 if(SUCCEEDED(hr)) 702 { 703 ComPtr <IWbemServices> pSvc; 704 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 705 if(SUCCEEDED(hr)) 706 { 707 ComPtr <IWbemClassObject> pAdapterConfig; 708 hr = netIfWinFindAdapterClassById(pSvc, &guid, pAdapterConfig.asOutParam()); 709 if(SUCCEEDED(hr)) 710 { 711 BSTR ObjPath; 712 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 713 if(SUCCEEDED(hr)) 714 { 715 hr = netIfWinEnableStaticV4V6(pSvc, ObjPath, aIPV6Address, aIPV6Mask); 716 if(SUCCEEDED(hr)) 717 { 718 hr = netIfWinSetGatewaysV4V6(pSvc, ObjPath, aIPV6DefaultGateway); 719 if(SUCCEEDED(hr)) 720 { 721 hr = netIfWinUpdateConfig(pIf); 722 } 723 } 724 SysFreeString(ObjPath); 725 } 726 } 727 } 728 } 729 730 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 731 } 732 733 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway) 734 { 735 return VERR_GENERAL_FAILURE; 736 } 737 738 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf) 739 { 740 HRESULT hr; 741 GUID guid; 742 hr = pIf->COMGETTER(Id) (&guid); 743 if(SUCCEEDED(hr)) 744 { 745 ComPtr <IWbemServices> pSvc; 746 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); 747 if(SUCCEEDED(hr)) 748 { 749 ComPtr <IWbemClassObject> pAdapterConfig; 750 hr = netIfWinFindAdapterClassById(pSvc, &guid, pAdapterConfig.asOutParam()); 751 if(SUCCEEDED(hr)) 752 { 753 BSTR ObjPath; 754 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath); 755 if(SUCCEEDED(hr)) 756 { 757 hr = netIfWinEnableDHCP(pSvc, ObjPath); 758 if(SUCCEEDED(hr)) 759 { 760 hr = netIfWinUpdateConfig(pIf); 761 } 762 SysFreeString(ObjPath); 763 } 764 } 765 } 766 } 767 768 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 769 } 770 500 771 # define VBOX_APP_NAME L"VirtualBox" 501 772 … … 686 957 return VINF_SUCCESS; 687 958 } 688 689 //TODO: this is sample currently, hardcoded balues should be removed and exposed to the API690 #if 0691 static int NetIfEnableStatic()692 {693 INetCfg *pnc;694 LPWSTR lpszLockedBy = NULL;695 int r = 1;696 HRESULT hr;697 698 hr = VBoxNetCfgWinQueryINetCfg(FALSE, VBOX_APP_NAME, &pnc, &lpszLockedBy);699 if(hr == S_OK)700 {701 INetCfgComponent *pComponent;702 HRESULT hr = pnc->FindComponent(L"*msloop", &pComponent);703 if(hr == S_OK)704 {705 GUID guid;706 hr = pComponent->GetInstanceGuid(&guid);707 if(SUCCEEDED(hr))708 {709 IWbemServices * pSvc;710 hr = netIfWinCreateIWbemServices(&pSvc);711 if(SUCCEEDED(hr))712 {713 IWbemClassObject *pAdapterConfig;714 hr = netIfWinFindAdapterClassById(pSvc, &guid, &pAdapterConfig);715 if(SUCCEEDED(hr))716 {717 in_addr ip[1];718 in_addr mask[1];719 ip[0].S_un.S_addr = inet_addr("192.168.5.1");720 mask[0].S_un.S_addr = inet_addr("255.255.255.0");721 722 hr = VBoxNetCfgWinEnableStatic(pSvc, pAdapterConfig, ip, mask, 1);723 if(SUCCEEDED(hr))724 {725 printf("succees!!!\n");726 r = 0;727 }728 }729 }730 731 }732 }733 }734 735 736 return r;737 }738 #endif739 959 740 960 int NetIfList(std::list <ComObjPtr <HostNetworkInterface> > &list)
Note:
See TracChangeset
for help on using the changeset viewer.