VirtualBox

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

Last change on this file since 71253 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

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