VirtualBox

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

Last change on this file since 67954 was 67636, checked in by vboxsync, 7 years ago

Main/HostNetworkInterfaceImpl: enableStaticIPConfigV6 - Fix inverted
comparison in r116403.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.9 KB
Line 
1/* $Id: HostNetworkInterfaceImpl.cpp 67636 2017-06-27 13:20:06Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2016 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.bDhcpEnabled;
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 return S_OK;
186 }
187 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
188}
189
190Bstr HostNetworkInterface::i_composeNetworkName(const Utf8Str aShortName)
191{
192 return Utf8Str("HostInterfaceNetworking-").append(aShortName);
193}
194/**
195 * Initializes the host object.
196 *
197 * @returns COM result indicator
198 * @param aInterfaceName name of the network interface
199 * @param aGuid GUID of the host network interface
200 */
201HRESULT HostNetworkInterface::init(Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
202{
203// LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
204// aInterfaceName.raw(), aGuid.toString().raw()));
205
206// ComAssertRet(aInterfaceName, E_INVALIDARG);
207// ComAssertRet(aGuid.isValid(), E_INVALIDARG);
208 ComAssertRet(pIf, E_INVALIDARG);
209
210 /* Enclose the state transition NotReady->InInit->Ready */
211 AutoInitSpan autoInitSpan(this);
212 AssertReturn(autoInitSpan.isOk(), E_FAIL);
213
214 unconst(mInterfaceName) = aInterfaceName;
215 unconst(mGuid) = pIf->Uuid;
216 if (pIf->szShortName[0])
217 {
218 unconst(mNetworkName) = i_composeNetworkName(pIf->szShortName);
219 unconst(mShortName) = pIf->szShortName;
220 }
221 else
222 {
223 unconst(mNetworkName) = i_composeNetworkName(aInterfaceName);
224 unconst(mShortName) = aInterfaceName;
225 }
226 mIfType = ifType;
227
228 int iPrefixIPv6;
229
230 m.realIPAddress = m.IPAddress = pIf->IPAddress.u;
231 m.realNetworkMask = m.networkMask = pIf->IPNetMask.u;
232 if (pIf->IPv6Address.s.Lo || pIf->IPv6Address.s.Hi)
233 m.realIPV6Address = m.IPV6Address = Bstr(Utf8StrFmt("%RTnaipv6", &pIf->IPv6Address));
234 else
235 m.realIPV6Address = m.IPV6Address = Bstr("");
236 RTNetMaskToPrefixIPv6(&pIf->IPv6NetMask, &iPrefixIPv6);
237 m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = iPrefixIPv6;
238 m.dhcpEnabled = pIf->bDhcpEnabled;
239 m.hardwareAddress = Bstr(Utf8StrFmt("%RTmac", &pIf->MACAddress));
240#ifdef RT_OS_WINDOWS
241 m.mediumType = (HostNetworkInterfaceMediumType)pIf->enmMediumType;
242 m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
243#else /* !RT_OS_WINDOWS */
244 m.mediumType = pIf->enmMediumType;
245 m.status = pIf->enmStatus;
246#endif /* !RT_OS_WINDOWS */
247 m.speedMbits = pIf->uSpeedMbits;
248
249 /* Confirm a successful initialization */
250 autoInitSpan.setSucceeded();
251
252 return S_OK;
253}
254#endif
255
256// wrapped IHostNetworkInterface properties
257/////////////////////////////////////////////////////////////////////////////
258/**
259 * Returns the name of the host network interface.
260 *
261 * @returns COM status code
262 * @param aInterfaceName - Interface Name
263 */
264
265HRESULT HostNetworkInterface::getName(com::Utf8Str &aInterfaceName)
266{
267 aInterfaceName = mInterfaceName;
268 return S_OK;
269}
270
271/**
272 * Returns the short name of the host network interface.
273 *
274 * @returns COM status code
275 * @param aShortName Short Name
276 */
277
278HRESULT HostNetworkInterface::getShortName(com::Utf8Str &aShortName)
279{
280 aShortName = mShortName;
281
282 return S_OK;
283}
284
285/**
286 * Returns the GUID of the host network interface.
287 *
288 * @returns COM status code
289 * @param aGuid GUID
290 */
291HRESULT HostNetworkInterface::getId(com::Guid &aGuid)
292{
293 aGuid = mGuid;
294
295 return S_OK;
296}
297
298HRESULT HostNetworkInterface::getDHCPEnabled(BOOL *aDHCPEnabled)
299{
300 *aDHCPEnabled = m.dhcpEnabled;
301
302 return S_OK;
303}
304
305
306/**
307 * Returns the IP address of the host network interface.
308 *
309 * @returns COM status code
310 * @param aIPAddress Address name
311 */
312HRESULT HostNetworkInterface::getIPAddress(com::Utf8Str &aIPAddress)
313{
314 in_addr tmp;
315#if defined(RT_OS_WINDOWS)
316 tmp.S_un.S_addr = m.IPAddress;
317#else
318 tmp.s_addr = m.IPAddress;
319#endif
320 char *addr = inet_ntoa(tmp);
321 if (addr)
322 {
323 aIPAddress = addr;
324 return S_OK;
325 }
326
327 return E_FAIL;
328}
329
330/**
331 * Returns the netwok mask of the host network interface.
332 *
333 * @returns COM status code
334 * @param aNetworkMask name.
335 */
336HRESULT HostNetworkInterface::getNetworkMask(com::Utf8Str &aNetworkMask)
337{
338
339 in_addr tmp;
340#if defined(RT_OS_WINDOWS)
341 tmp.S_un.S_addr = m.networkMask;
342#else
343 tmp.s_addr = m.networkMask;
344#endif
345 char *addr = inet_ntoa(tmp);
346 if (addr)
347 {
348 aNetworkMask = Utf8Str(addr);
349 return S_OK;
350 }
351
352 return E_FAIL;
353}
354
355HRESULT HostNetworkInterface::getIPV6Supported(BOOL *aIPV6Supported)
356{
357#if defined(RT_OS_WINDOWS)
358 *aIPV6Supported = FALSE;
359#else
360 *aIPV6Supported = TRUE;
361#endif
362
363 return S_OK;
364}
365
366/**
367 * Returns the IP V6 address of the host network interface.
368 *
369 * @returns COM status code
370 * @param aIPV6Address
371 */
372HRESULT HostNetworkInterface::getIPV6Address(com::Utf8Str &aIPV6Address)
373{
374 aIPV6Address = m.IPV6Address;
375 return S_OK;
376}
377
378/**
379 * Returns the IP V6 network mask prefix length of the host network interface.
380 *
381 * @returns COM status code
382 * @param aIPV6NetworkMaskPrefixLength address of result pointer
383 */
384HRESULT HostNetworkInterface::getIPV6NetworkMaskPrefixLength(ULONG *aIPV6NetworkMaskPrefixLength)
385{
386 *aIPV6NetworkMaskPrefixLength = m.IPV6NetworkMaskPrefixLength;
387
388 return S_OK;
389}
390
391/**
392 * Returns the hardware address of the host network interface.
393 *
394 * @returns COM status code
395 * @param aHardwareAddress hardware address
396 */
397HRESULT HostNetworkInterface::getHardwareAddress(com::Utf8Str &aHardwareAddress)
398{
399 aHardwareAddress = m.hardwareAddress;
400 return S_OK;
401}
402
403/**
404 * Returns the encapsulation protocol type of the host network interface.
405 *
406 * @returns COM status code
407 * @param aType address of result pointer
408 */
409HRESULT HostNetworkInterface::getMediumType(HostNetworkInterfaceMediumType_T *aType)
410{
411 *aType = m.mediumType;
412
413 return S_OK;
414}
415
416/**
417 * Returns the current state of the host network interface.
418 *
419 * @returns COM status code
420 * @param aStatus address of result pointer
421 */
422HRESULT HostNetworkInterface::getStatus(HostNetworkInterfaceStatus_T *aStatus)
423{
424 *aStatus = m.status;
425
426 return S_OK;
427}
428
429/**
430 * Returns network interface type
431 *
432 * @returns COM status code
433 * @param aType address of result pointer
434 */
435HRESULT HostNetworkInterface::getInterfaceType(HostNetworkInterfaceType_T *aType)
436{
437 *aType = mIfType;
438
439 return S_OK;
440
441}
442
443HRESULT HostNetworkInterface::getNetworkName(com::Utf8Str &aNetworkName)
444{
445 aNetworkName = mNetworkName;
446
447 return S_OK;
448}
449
450HRESULT HostNetworkInterface::enableStaticIPConfig(const com::Utf8Str &aIPAddress,
451 const com::Utf8Str &aNetworkMask)
452{
453#ifndef VBOX_WITH_HOSTNETIF_API
454 return E_NOTIMPL;
455#else
456 if (aIPAddress.isEmpty())
457 {
458 if (m.IPAddress)
459 {
460 int rc = NetIfEnableStaticIpConfig(mVirtualBox, this, m.IPAddress, 0, 0);
461 if (RT_SUCCESS(rc))
462 {
463 m.realIPAddress = 0;
464 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress",
465 mInterfaceName.raw()).raw(), NULL)))
466 return E_FAIL;
467 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask",
468 mInterfaceName.raw()).raw(), NULL)))
469 return E_FAIL;
470 return S_OK;
471 }
472 }
473 else
474 return S_OK;
475 }
476
477 ULONG ip, mask;
478 ip = inet_addr(aIPAddress.c_str());
479 if (ip != INADDR_NONE)
480 {
481 if (aNetworkMask.isEmpty())
482 mask = 0xFFFFFF;
483 else
484 mask = inet_addr(aNetworkMask.c_str());
485 if (mask != INADDR_NONE)
486 {
487 if (m.realIPAddress == ip && m.realNetworkMask == mask)
488 return S_OK;
489 int rc = NetIfEnableStaticIpConfig(mVirtualBox, this, m.IPAddress, ip, mask);
490 if (RT_SUCCESS(rc))
491 {
492 m.realIPAddress = ip;
493 m.realNetworkMask = mask;
494 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress",
495 mInterfaceName.raw()).raw(),
496 Bstr(aIPAddress).raw())))
497 return E_FAIL;
498 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask",
499 mInterfaceName.raw()).raw(),
500 Bstr(aNetworkMask).raw())))
501 return E_FAIL;
502 return S_OK;
503 }
504 else
505 {
506 LogRel(("Failed to EnableStaticIpConfig with rc=%Rrc\n", rc));
507 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
508 }
509
510 }
511 }
512 return E_FAIL;
513#endif
514}
515
516HRESULT HostNetworkInterface::enableStaticIPConfigV6(const com::Utf8Str &aIPV6Address,
517 ULONG aIPV6NetworkMaskPrefixLength)
518{
519#ifndef VBOX_WITH_HOSTNETIF_API
520 return E_NOTIMPL;
521#else
522 if (aIPV6NetworkMaskPrefixLength > 128)
523 return mVirtualBox->setErrorBoth(E_INVALIDARG, VERR_INVALID_PARAMETER,
524 "Invalid IPv6 prefix length");
525
526 int rc;
527
528 RTNETADDRIPV6 AddrOld, AddrNew;
529 char *pszZoneIgnored;
530 bool fAddrChanged;
531
532 rc = RTNetStrToIPv6Addr(aIPV6Address.c_str(), &AddrNew, &pszZoneIgnored);
533 if (RT_FAILURE(rc))
534 {
535 return mVirtualBox->setErrorBoth(E_INVALIDARG, rc, "Invalid IPv6 address");
536 }
537
538 rc = RTNetStrToIPv6Addr(com::Utf8Str(m.realIPV6Address).c_str(), &AddrOld, &pszZoneIgnored);
539 if (RT_SUCCESS(rc))
540 {
541 fAddrChanged = (AddrNew.s.Lo != AddrOld.s.Lo || AddrNew.s.Hi != AddrOld.s.Hi);
542 }
543 else
544 {
545 fAddrChanged = true;
546 }
547
548 if ( fAddrChanged
549 || m.realIPV6PrefixLength != aIPV6NetworkMaskPrefixLength)
550 {
551 BSTR bstr;
552 aIPV6Address.cloneTo(&bstr);
553 if (aIPV6NetworkMaskPrefixLength == 0)
554 aIPV6NetworkMaskPrefixLength = 64;
555 rc = NetIfEnableStaticIpConfigV6(mVirtualBox, this, m.IPV6Address.raw(),
556 bstr, aIPV6NetworkMaskPrefixLength);
557 if (RT_FAILURE(rc))
558 {
559 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Rrc\n", rc));
560 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
561 }
562 else
563 {
564 m.realIPV6Address = aIPV6Address;
565 m.realIPV6PrefixLength = aIPV6NetworkMaskPrefixLength;
566 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%ls/IPV6Address",
567 mInterfaceName.raw()).raw(),
568 Bstr(aIPV6Address).raw())))
569 return E_FAIL;
570 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%ls/IPV6NetMask",
571 mInterfaceName.raw()).raw(),
572 BstrFmt("%u", aIPV6NetworkMaskPrefixLength).raw())))
573 return E_FAIL;
574 }
575
576 }
577 return S_OK;
578#endif
579}
580
581HRESULT HostNetworkInterface::enableDynamicIPConfig()
582{
583#ifndef VBOX_WITH_HOSTNETIF_API
584 return E_NOTIMPL;
585#else
586 int rc = NetIfEnableDynamicIpConfig(mVirtualBox, this);
587 if (RT_FAILURE(rc))
588 {
589 LogRel(("Failed to EnableDynamicIpConfig with rc=%Rrc\n", rc));
590 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
591 }
592 return S_OK;
593#endif
594}
595
596HRESULT HostNetworkInterface::dHCPRediscover()
597{
598#ifndef VBOX_WITH_HOSTNETIF_API
599 return E_NOTIMPL;
600#else
601 int rc = NetIfDhcpRediscover(mVirtualBox, this);
602 if (RT_FAILURE(rc))
603 {
604 LogRel(("Failed to DhcpRediscover with rc=%Rrc\n", rc));
605 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
606 }
607 return S_OK;
608#endif
609}
610
611HRESULT HostNetworkInterface::i_setVirtualBox(VirtualBox *pVirtualBox)
612{
613 AutoCaller autoCaller(this);
614 if (FAILED(autoCaller.rc())) return autoCaller.rc();
615
616 AssertReturn(mVirtualBox != pVirtualBox, S_OK);
617
618 unconst(mVirtualBox) = pVirtualBox;
619
620#if !defined(RT_OS_WINDOWS)
621 /* If IPv4 address hasn't been initialized */
622 if (m.IPAddress == 0 && mIfType == HostNetworkInterfaceType_HostOnly)
623 {
624 Bstr tmpAddr, tmpMask;
625 HRESULT hrc = mVirtualBox->GetExtraData(BstrFmt("HostOnly/%ls/IPAddress",
626 mInterfaceName.raw()).raw(),
627 tmpAddr.asOutParam());
628 if (FAILED(hrc) || tmpAddr.isEmpty())
629 tmpAddr = getDefaultIPv4Address(mInterfaceName);
630
631 hrc = mVirtualBox->GetExtraData(BstrFmt("HostOnly/%ls/IPNetMask",
632 mInterfaceName.raw()).raw(),
633 tmpMask.asOutParam());
634 if (FAILED(hrc) || tmpMask.isEmpty())
635 tmpMask = Bstr(VBOXNET_IPV4MASK_DEFAULT);
636
637 m.IPAddress = inet_addr(Utf8Str(tmpAddr).c_str());
638 m.networkMask = inet_addr(Utf8Str(tmpMask).c_str());
639 }
640
641 if (m.IPV6Address.isEmpty())
642 {
643 Bstr tmpPrefixLen;
644 HRESULT hrc = mVirtualBox->GetExtraData(BstrFmt("HostOnly/%ls/IPV6Address",
645 mInterfaceName.raw()).raw(),
646 m.IPV6Address.asOutParam());
647 if (SUCCEEDED(hrc) && !m.IPV6Address.isEmpty())
648 {
649 hrc = mVirtualBox->GetExtraData(BstrFmt("HostOnly/%ls/IPV6PrefixLen",
650 mInterfaceName.raw()).raw(),
651 tmpPrefixLen.asOutParam());
652 if (SUCCEEDED(hrc) && !tmpPrefixLen.isEmpty())
653 m.IPV6NetworkMaskPrefixLength = Utf8Str(tmpPrefixLen).toUInt32();
654 else
655 m.IPV6NetworkMaskPrefixLength = 64;
656 }
657 }
658#endif
659
660 return S_OK;
661}
662
663/* 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