VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp@ 43907

Last change on this file since 43907 was 43629, checked in by vboxsync, 12 years ago

Main/Metrics: Linux fs/disk metrics, VBoxManage filtering + minor fixes (#6345)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.6 KB
Line 
1/* $Id: HostNetworkInterfaceImpl.cpp 43629 2012-10-12 09:26:07Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2012 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "HostNetworkInterfaceImpl.h"
21#include "AutoCaller.h"
22#include "Logging.h"
23#include "netif.h"
24#include "Performance.h"
25#include "PerformanceImpl.h"
26
27#include <iprt/cpp/utils.h>
28
29#ifdef RT_OS_FREEBSD
30# include <netinet/in.h> /* INADDR_NONE */
31#endif /* RT_OS_FREEBSD */
32
33// constructor / destructor
34/////////////////////////////////////////////////////////////////////////////
35
36HostNetworkInterface::HostNetworkInterface()
37 : mVBox(NULL)
38{
39}
40
41HostNetworkInterface::~HostNetworkInterface()
42{
43}
44
45HRESULT HostNetworkInterface::FinalConstruct()
46{
47 return BaseFinalConstruct();
48}
49
50void HostNetworkInterface::FinalRelease()
51{
52 uninit();
53 BaseFinalRelease();
54}
55
56// public initializer/uninitializer for internal purposes only
57/////////////////////////////////////////////////////////////////////////////
58
59/**
60 * Initializes the host object.
61 *
62 * @returns COM result indicator
63 * @param aInterfaceName name of the network interface
64 * @param aGuid GUID of the host network interface
65 */
66HRESULT HostNetworkInterface::init(Bstr aInterfaceName, Bstr aShortName, Guid aGuid, HostNetworkInterfaceType_T ifType)
67{
68 LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
69 aInterfaceName.raw(), aGuid.toString().c_str()));
70
71 ComAssertRet(!aInterfaceName.isEmpty(), E_INVALIDARG);
72 ComAssertRet(!aGuid.isEmpty(), E_INVALIDARG);
73
74 /* Enclose the state transition NotReady->InInit->Ready */
75 AutoInitSpan autoInitSpan(this);
76 AssertReturn(autoInitSpan.isOk(), E_FAIL);
77
78 unconst(mInterfaceName) = aInterfaceName;
79 unconst(mNetworkName) = composeNetworkName(aShortName);
80 unconst(mGuid) = aGuid;
81 mIfType = ifType;
82
83 /* Confirm a successful initialization */
84 autoInitSpan.setSucceeded();
85
86 return S_OK;
87}
88
89void HostNetworkInterface::registerMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr)
90{
91 LogFlowThisFunc(("mShortName={%ls}, mInterfaceName={%ls}, mGuid={%s}, mSpeedMbits=%u\n",
92 mShortName.raw(), mInterfaceName.raw(), mGuid.toString().c_str(), m.speedMbits));
93 pm::CollectorHAL *hal = aCollector->getHAL();
94 /* Create sub metrics */
95 Utf8StrFmt strName("Net/%ls/Load", mShortName.raw());
96 pm::SubMetric *networkLoadRx = new pm::SubMetric(strName + "/Rx",
97 "Percentage of network interface receive bandwidth used.");
98 pm::SubMetric *networkLoadTx = new pm::SubMetric(strName + "/Tx",
99 "Percentage of network interface transmit bandwidth used.");
100
101 /* Create and register base metrics */
102 pm::BaseMetric *networkLoad = new pm::HostNetworkLoadRaw(hal, objptr, strName, Utf8Str(mShortName), Utf8Str(mInterfaceName), m.speedMbits, networkLoadRx, networkLoadTx);
103 aCollector->registerBaseMetric(networkLoad);
104
105 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx, 0));
106 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx,
107 new pm::AggregateAvg()));
108 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx,
109 new pm::AggregateMin()));
110 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx,
111 new pm::AggregateMax()));
112
113 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx, 0));
114 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx,
115 new pm::AggregateAvg()));
116 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx,
117 new pm::AggregateMin()));
118 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx,
119 new pm::AggregateMax()));
120}
121
122void HostNetworkInterface::unregisterMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr)
123{
124 LogFlowThisFunc(("mShortName={%ls}, mInterfaceName={%ls}, mGuid={%s}\n",
125 mShortName.raw(), mInterfaceName.raw(), mGuid.toString().c_str()));
126 Utf8StrFmt name("Net/%ls/Load", mShortName.raw());
127 aCollector->unregisterMetricsFor(objptr, name + "/*");
128 aCollector->unregisterBaseMetricsFor(objptr, name);
129}
130
131#ifdef VBOX_WITH_HOSTNETIF_API
132
133HRESULT HostNetworkInterface::updateConfig()
134{
135 NETIFINFO info;
136 int rc = NetIfGetConfig(this, &info);
137 if (RT_SUCCESS(rc))
138 {
139 m.realIPAddress = m.IPAddress = info.IPAddress.u;
140 m.realNetworkMask = m.networkMask = info.IPNetMask.u;
141 m.dhcpEnabled = info.bDhcpEnabled;
142 m.realIPV6Address = m.IPV6Address = composeIPv6Address(&info.IPv6Address);
143 m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&info.IPv6NetMask);
144 m.hardwareAddress = composeHardwareAddress(&info.MACAddress);
145#ifdef RT_OS_WINDOWS
146 m.mediumType = (HostNetworkInterfaceMediumType)info.enmMediumType;
147 m.status = (HostNetworkInterfaceStatus)info.enmStatus;
148#else /* !RT_OS_WINDOWS */
149 m.mediumType = info.enmMediumType;
150 m.status = info.enmStatus;
151#endif /* !RT_OS_WINDOWS */
152 m.speedMbits = info.uSpeedMbits;
153 return S_OK;
154 }
155 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
156}
157
158Bstr HostNetworkInterface::composeNetworkName(const Utf8Str aShortName)
159{
160 return Utf8Str("HostInterfaceNetworking-").append(aShortName);
161}
162/**
163 * Initializes the host object.
164 *
165 * @returns COM result indicator
166 * @param aInterfaceName name of the network interface
167 * @param aGuid GUID of the host network interface
168 */
169HRESULT HostNetworkInterface::init(Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
170{
171// LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
172// aInterfaceName.raw(), aGuid.toString().raw()));
173
174// ComAssertRet(aInterfaceName, E_INVALIDARG);
175// ComAssertRet(!aGuid.isEmpty(), E_INVALIDARG);
176 ComAssertRet(pIf, E_INVALIDARG);
177
178 /* Enclose the state transition NotReady->InInit->Ready */
179 AutoInitSpan autoInitSpan(this);
180 AssertReturn(autoInitSpan.isOk(), E_FAIL);
181
182 unconst(mInterfaceName) = aInterfaceName;
183 unconst(mGuid) = pIf->Uuid;
184 if (pIf->szShortName[0])
185 {
186 unconst(mNetworkName) = composeNetworkName(pIf->szShortName);
187 unconst(mShortName) = pIf->szShortName;
188 }
189 else
190 {
191 unconst(mNetworkName) = composeNetworkName(aInterfaceName);
192 unconst(mShortName) = aInterfaceName;
193 }
194 mIfType = ifType;
195
196 m.realIPAddress = m.IPAddress = pIf->IPAddress.u;
197 m.realNetworkMask = m.networkMask = pIf->IPNetMask.u;
198 m.realIPV6Address = m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
199 m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&pIf->IPv6NetMask);
200 m.dhcpEnabled = pIf->bDhcpEnabled;
201 m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
202#ifdef RT_OS_WINDOWS
203 m.mediumType = (HostNetworkInterfaceMediumType)pIf->enmMediumType;
204 m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
205#else /* !RT_OS_WINDOWS */
206 m.mediumType = pIf->enmMediumType;
207 m.status = pIf->enmStatus;
208#endif /* !RT_OS_WINDOWS */
209 m.speedMbits = pIf->uSpeedMbits;
210
211 /* Confirm a successful initialization */
212 autoInitSpan.setSucceeded();
213
214 return S_OK;
215}
216#endif
217
218// IHostNetworkInterface properties
219/////////////////////////////////////////////////////////////////////////////
220
221/**
222 * Returns the name of the host network interface.
223 *
224 * @returns COM status code
225 * @param aInterfaceName address of result pointer
226 */
227STDMETHODIMP HostNetworkInterface::COMGETTER(Name)(BSTR *aInterfaceName)
228{
229 CheckComArgOutPointerValid(aInterfaceName);
230
231 AutoCaller autoCaller(this);
232 if (FAILED(autoCaller.rc())) return autoCaller.rc();
233
234 mInterfaceName.cloneTo(aInterfaceName);
235
236 return S_OK;
237}
238
239/**
240 * Returns the GUID of the host network interface.
241 *
242 * @returns COM status code
243 * @param aGuid address of result pointer
244 */
245STDMETHODIMP HostNetworkInterface::COMGETTER(Id)(BSTR *aGuid)
246{
247 CheckComArgOutPointerValid(aGuid);
248
249 AutoCaller autoCaller(this);
250 if (FAILED(autoCaller.rc())) return autoCaller.rc();
251
252 mGuid.toUtf16().cloneTo(aGuid);
253
254 return S_OK;
255}
256
257STDMETHODIMP HostNetworkInterface::COMGETTER(DHCPEnabled)(BOOL *aDHCPEnabled)
258{
259 CheckComArgOutPointerValid(aDHCPEnabled);
260
261 AutoCaller autoCaller(this);
262 if (FAILED(autoCaller.rc())) return autoCaller.rc();
263
264 *aDHCPEnabled = m.dhcpEnabled;
265
266 return S_OK;
267}
268
269
270/**
271 * Returns the IP address of the host network interface.
272 *
273 * @returns COM status code
274 * @param aIPAddress address of result pointer
275 */
276STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress)(BSTR *aIPAddress)
277{
278 CheckComArgOutPointerValid(aIPAddress);
279
280 AutoCaller autoCaller(this);
281 if (FAILED(autoCaller.rc())) return autoCaller.rc();
282
283 in_addr tmp;
284#if defined(RT_OS_WINDOWS)
285 tmp.S_un.S_addr = m.IPAddress;
286#else
287 tmp.s_addr = m.IPAddress;
288#endif
289 char *addr = inet_ntoa(tmp);
290 if (addr)
291 {
292 Bstr(addr).detachTo(aIPAddress);
293 return S_OK;
294 }
295
296 return E_FAIL;
297}
298
299/**
300 * Returns the netwok mask of the host network interface.
301 *
302 * @returns COM status code
303 * @param aNetworkMask address of result pointer
304 */
305STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask)(BSTR *aNetworkMask)
306{
307 CheckComArgOutPointerValid(aNetworkMask);
308
309 AutoCaller autoCaller(this);
310 if (FAILED(autoCaller.rc())) return autoCaller.rc();
311
312 in_addr tmp;
313#if defined(RT_OS_WINDOWS)
314 tmp.S_un.S_addr = m.networkMask;
315#else
316 tmp.s_addr = m.networkMask;
317#endif
318 char *addr = inet_ntoa(tmp);
319 if (addr)
320 {
321 Bstr(addr).detachTo(aNetworkMask);
322 return S_OK;
323 }
324
325 return E_FAIL;
326}
327
328STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Supported)(BOOL *aIPV6Supported)
329{
330 CheckComArgOutPointerValid(aIPV6Supported);
331#if defined(RT_OS_WINDOWS)
332 *aIPV6Supported = FALSE;
333#else
334 *aIPV6Supported = TRUE;
335#endif
336
337 return S_OK;
338}
339
340/**
341 * Returns the IP V6 address of the host network interface.
342 *
343 * @returns COM status code
344 * @param aIPV6Address address of result pointer
345 */
346STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address)(BSTR *aIPV6Address)
347{
348 CheckComArgOutPointerValid(aIPV6Address);
349
350 AutoCaller autoCaller(this);
351 if (FAILED(autoCaller.rc())) return autoCaller.rc();
352
353 m.IPV6Address.cloneTo(aIPV6Address);
354
355 return S_OK;
356}
357
358/**
359 * Returns the IP V6 network mask of the host network interface.
360 *
361 * @returns COM status code
362 * @param aIPV6Mask address of result pointer
363 */
364STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMaskPrefixLength)(ULONG *aIPV6NetworkMaskPrefixLength)
365{
366 CheckComArgOutPointerValid(aIPV6NetworkMaskPrefixLength);
367
368 AutoCaller autoCaller(this);
369 if (FAILED(autoCaller.rc())) return autoCaller.rc();
370
371 *aIPV6NetworkMaskPrefixLength = m.IPV6NetworkMaskPrefixLength;
372
373 return S_OK;
374}
375
376/**
377 * Returns the hardware address of the host network interface.
378 *
379 * @returns COM status code
380 * @param aHardwareAddress address of result pointer
381 */
382STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress)(BSTR *aHardwareAddress)
383{
384 CheckComArgOutPointerValid(aHardwareAddress);
385
386 AutoCaller autoCaller(this);
387 if (FAILED(autoCaller.rc())) return autoCaller.rc();
388
389 m.hardwareAddress.cloneTo(aHardwareAddress);
390
391 return S_OK;
392}
393
394/**
395 * Returns the encapsulation protocol type of the host network interface.
396 *
397 * @returns COM status code
398 * @param aType address of result pointer
399 */
400STDMETHODIMP HostNetworkInterface::COMGETTER(MediumType)(HostNetworkInterfaceMediumType_T *aType)
401{
402 CheckComArgOutPointerValid(aType);
403
404 AutoCaller autoCaller(this);
405 if (FAILED(autoCaller.rc())) return autoCaller.rc();
406
407 *aType = m.mediumType;
408
409 return S_OK;
410}
411
412/**
413 * Returns the current state of the host network interface.
414 *
415 * @returns COM status code
416 * @param aStatus address of result pointer
417 */
418STDMETHODIMP HostNetworkInterface::COMGETTER(Status)(HostNetworkInterfaceStatus_T *aStatus)
419{
420 CheckComArgOutPointerValid(aStatus);
421
422 AutoCaller autoCaller(this);
423 if (FAILED(autoCaller.rc())) return autoCaller.rc();
424
425 *aStatus = m.status;
426
427 return S_OK;
428}
429
430/**
431 * Returns network interface type
432 *
433 * @returns COM status code
434 * @param aType address of result pointer
435 */
436STDMETHODIMP HostNetworkInterface::COMGETTER(InterfaceType)(HostNetworkInterfaceType_T *aType)
437{
438 CheckComArgOutPointerValid(aType);
439
440 AutoCaller autoCaller(this);
441 if (FAILED(autoCaller.rc())) return autoCaller.rc();
442
443 *aType = mIfType;
444
445 return S_OK;
446
447}
448
449STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkName)(BSTR *aNetworkName)
450{
451 CheckComArgOutPointerValid(aNetworkName);
452
453 AutoCaller autoCaller(this);
454 if (FAILED(autoCaller.rc())) return autoCaller.rc();
455
456 mNetworkName.cloneTo(aNetworkName);
457
458 return S_OK;
459}
460
461STDMETHODIMP HostNetworkInterface::EnableStaticIPConfig(IN_BSTR aIPAddress, IN_BSTR aNetMask)
462{
463#ifndef VBOX_WITH_HOSTNETIF_API
464 return E_NOTIMPL;
465#else
466 AutoCaller autoCaller(this);
467 if (FAILED(autoCaller.rc())) return autoCaller.rc();
468
469 if (Bstr(aIPAddress).isEmpty())
470 {
471 if (m.IPAddress)
472 {
473 int rc = NetIfEnableStaticIpConfig(mVBox, this, m.IPAddress, 0, 0);
474 if (RT_SUCCESS(rc))
475 {
476 m.realIPAddress = 0;
477 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()).raw(), NULL)))
478 return E_FAIL;
479 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()).raw(), NULL)))
480 return E_FAIL;
481 return S_OK;
482 }
483 }
484 else
485 return S_OK;
486 }
487
488 ULONG ip, mask;
489 ip = inet_addr(Utf8Str(aIPAddress).c_str());
490 if (ip != INADDR_NONE)
491 {
492 if (Bstr(aNetMask).isEmpty())
493 mask = 0xFFFFFF;
494 else
495 mask = inet_addr(Utf8Str(aNetMask).c_str());
496 if (mask != INADDR_NONE)
497 {
498 if (m.realIPAddress == ip && m.realNetworkMask == mask)
499 return S_OK;
500 int rc = NetIfEnableStaticIpConfig(mVBox, this, m.IPAddress, ip, mask);
501 if (RT_SUCCESS(rc))
502 {
503 m.realIPAddress = ip;
504 m.realNetworkMask = mask;
505 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()).raw(),
506 Bstr(aIPAddress).raw())))
507 return E_FAIL;
508 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()).raw(),
509 Bstr(aNetMask).raw())))
510 return E_FAIL;
511 return S_OK;
512 }
513 else
514 {
515 LogRel(("Failed to EnableStaticIpConfig with rc=%Rrc\n", rc));
516 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
517 }
518
519 }
520 }
521 return E_FAIL;
522#endif
523}
524
525STDMETHODIMP HostNetworkInterface::EnableStaticIPConfigV6(IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
526{
527#ifndef VBOX_WITH_HOSTNETIF_API
528 return E_NOTIMPL;
529#else
530 if (!aIPV6Address)
531 return E_INVALIDARG;
532 if (aIPV6MaskPrefixLength > 128)
533 return E_INVALIDARG;
534
535 AutoCaller autoCaller(this);
536 if (FAILED(autoCaller.rc())) return autoCaller.rc();
537
538 int rc = S_OK;
539 if (m.realIPV6Address != aIPV6Address || m.realIPV6PrefixLength != aIPV6MaskPrefixLength)
540 {
541 if (aIPV6MaskPrefixLength == 0)
542 aIPV6MaskPrefixLength = 64;
543 rc = NetIfEnableStaticIpConfigV6(mVBox, this, m.IPV6Address.raw(), aIPV6Address, aIPV6MaskPrefixLength);
544 if (RT_FAILURE(rc))
545 {
546 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Rrc\n", rc));
547 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
548 }
549 else
550 {
551 m.realIPV6Address = aIPV6Address;
552 m.realIPV6PrefixLength = aIPV6MaskPrefixLength;
553 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", mInterfaceName.raw()).raw(),
554 Bstr(aIPV6Address).raw())))
555 return E_FAIL;
556 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPV6NetMask", mInterfaceName.raw()).raw(),
557 BstrFmt("%u", aIPV6MaskPrefixLength).raw())))
558 return E_FAIL;
559 }
560
561 }
562 return S_OK;
563#endif
564}
565
566STDMETHODIMP HostNetworkInterface::EnableDynamicIPConfig()
567{
568#ifndef VBOX_WITH_HOSTNETIF_API
569 return E_NOTIMPL;
570#else
571 AutoCaller autoCaller(this);
572 if (FAILED(autoCaller.rc())) return autoCaller.rc();
573
574 int rc = NetIfEnableDynamicIpConfig(mVBox, this);
575 if (RT_FAILURE(rc))
576 {
577 LogRel(("Failed to EnableDynamicIpConfig with rc=%Rrc\n", rc));
578 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
579 }
580 return S_OK;
581#endif
582}
583
584STDMETHODIMP HostNetworkInterface::DHCPRediscover()
585{
586#ifndef VBOX_WITH_HOSTNETIF_API
587 return E_NOTIMPL;
588#else
589 AutoCaller autoCaller(this);
590 if (FAILED(autoCaller.rc())) return autoCaller.rc();
591
592 int rc = NetIfDhcpRediscover(mVBox, this);
593 if (RT_FAILURE(rc))
594 {
595 LogRel(("Failed to DhcpRediscover with rc=%Rrc\n", rc));
596 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
597 }
598 return S_OK;
599#endif
600}
601
602HRESULT HostNetworkInterface::setVirtualBox(VirtualBox *pVBox)
603{
604 AutoCaller autoCaller(this);
605 if (FAILED(autoCaller.rc())) return autoCaller.rc();
606 AssertReturn(mVBox != pVBox, S_OK);
607
608 unconst(mVBox) = pVBox;
609
610#if !defined(RT_OS_WINDOWS)
611 /* If IPv4 address hasn't been initialized */
612 if (m.IPAddress == 0 && mIfType == HostNetworkInterfaceType_HostOnly)
613 {
614 Bstr tmpAddr, tmpMask;
615 HRESULT hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()).raw(),
616 tmpAddr.asOutParam());
617 if (FAILED(hrc) || tmpAddr.isEmpty())
618 tmpAddr = getDefaultIPv4Address(mInterfaceName);
619
620 hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()).raw(),
621 tmpMask.asOutParam());
622 if (FAILED(hrc) || tmpMask.isEmpty())
623 tmpMask = Bstr(VBOXNET_IPV4MASK_DEFAULT);
624
625 m.IPAddress = inet_addr(Utf8Str(tmpAddr).c_str());
626 m.networkMask = inet_addr(Utf8Str(tmpMask).c_str());
627 }
628
629 if (m.IPV6Address.isEmpty())
630 {
631 Bstr tmpPrefixLen;
632 HRESULT hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", mInterfaceName.raw()).raw(),
633 m.IPV6Address.asOutParam());
634 if (SUCCEEDED(hrc) && !m.IPV6Address.isEmpty())
635 {
636 hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPV6PrefixLen", mInterfaceName.raw()).raw(),
637 tmpPrefixLen.asOutParam());
638 if (SUCCEEDED(hrc) && !tmpPrefixLen.isEmpty())
639 m.IPV6NetworkMaskPrefixLength = Utf8Str(tmpPrefixLen).toUInt32();
640 else
641 m.IPV6NetworkMaskPrefixLength = 64;
642 }
643 }
644#endif
645
646 return S_OK;
647}
648
649/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette