VirtualBox

source: vbox/trunk/src/VBox/Main/HostNetworkInterfaceImpl.cpp@ 17698

Last change on this file since 17698 was 17613, checked in by vboxsync, 16 years ago

IHostNetworkInterface:: BSTR IPV6NetworkMask -> ULONG IPV6NetworkMaskPrefixLength

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1/* $Id: HostNetworkInterfaceImpl.cpp 17613 2009-03-10 10:34:42Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "HostNetworkInterfaceImpl.h"
25#include "Logging.h"
26#include "netif.h"
27
28// constructor / destructor
29/////////////////////////////////////////////////////////////////////////////
30
31DEFINE_EMPTY_CTOR_DTOR (HostNetworkInterface)
32
33HRESULT HostNetworkInterface::FinalConstruct()
34{
35 return S_OK;
36}
37
38void HostNetworkInterface::FinalRelease()
39{
40 uninit ();
41}
42
43// public initializer/uninitializer for internal purposes only
44/////////////////////////////////////////////////////////////////////////////
45
46/**
47 * Initializes the host object.
48 *
49 * @returns COM result indicator
50 * @param aInterfaceName name of the network interface
51 * @param aGuid GUID of the host network interface
52 */
53HRESULT HostNetworkInterface::init (Bstr aInterfaceName, Guid aGuid, HostNetworkInterfaceType_T ifType)
54{
55 LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
56 aInterfaceName.raw(), aGuid.toString().raw()));
57
58 ComAssertRet (aInterfaceName, E_INVALIDARG);
59 ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
60
61 /* Enclose the state transition NotReady->InInit->Ready */
62 AutoInitSpan autoInitSpan (this);
63 AssertReturn (autoInitSpan.isOk(), E_FAIL);
64
65 unconst (mInterfaceName) = aInterfaceName;
66 unconst (mGuid) = aGuid;
67 mIfType = ifType;
68
69
70 /* Confirm a successful initialization */
71 autoInitSpan.setSucceeded();
72
73 return S_OK;
74}
75
76#ifdef VBOX_WITH_HOSTNETIF_API
77
78HRESULT HostNetworkInterface::updateConfig ()
79{
80 NETIFINFO info;
81 int rc = NetIfGetConfig(this, &info);
82 if(RT_SUCCESS(rc))
83 {
84 m.IPAddress = info.IPAddress.u;
85 m.networkMask = info.IPNetMask.u;
86 m.IPV6Address = composeIPv6Address(&info.IPv6Address);
87 m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&info.IPv6NetMask);
88 m.hardwareAddress = composeHardwareAddress(&info.MACAddress);
89#ifdef RT_OS_WINDOWS
90 m.mediumType = (HostNetworkInterfaceMediumType)info.enmMediumType;
91 m.status = (HostNetworkInterfaceStatus)info.enmStatus;
92#else /* !RT_OS_WINDOWS */
93 m.mediumType = info.enmMediumType;
94 m.status = info.enmStatus;
95
96#endif /* !RT_OS_WINDOWS */
97 return S_OK;
98 }
99 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
100}
101
102/**
103 * Initializes the host object.
104 *
105 * @returns COM result indicator
106 * @param aInterfaceName name of the network interface
107 * @param aGuid GUID of the host network interface
108 */
109HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
110{
111// LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
112// aInterfaceName.raw(), aGuid.toString().raw()));
113
114// ComAssertRet (aInterfaceName, E_INVALIDARG);
115// ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
116 ComAssertRet (pIf, E_INVALIDARG);
117
118 /* Enclose the state transition NotReady->InInit->Ready */
119 AutoInitSpan autoInitSpan (this);
120 AssertReturn (autoInitSpan.isOk(), E_FAIL);
121
122 unconst (mInterfaceName) = aInterfaceName;
123 unconst (mGuid) = pIf->Uuid;
124 mIfType = ifType;
125
126 m.IPAddress = pIf->IPAddress.u;
127 m.networkMask = pIf->IPNetMask.u;
128 m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
129 m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&pIf->IPv6NetMask);
130 m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
131#ifdef RT_OS_WINDOWS
132 m.mediumType = (HostNetworkInterfaceMediumType)pIf->enmMediumType;
133 m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
134#else /* !RT_OS_WINDOWS */
135 m.mediumType = pIf->enmMediumType;
136 m.status = pIf->enmStatus;
137#endif /* !RT_OS_WINDOWS */
138
139 /* Confirm a successful initialization */
140 autoInitSpan.setSucceeded();
141
142 return S_OK;
143}
144#endif
145
146// IHostNetworkInterface properties
147/////////////////////////////////////////////////////////////////////////////
148
149/**
150 * Returns the name of the host network interface.
151 *
152 * @returns COM status code
153 * @param aInterfaceName address of result pointer
154 */
155STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
156{
157 CheckComArgOutPointerValid(aInterfaceName);
158
159 AutoCaller autoCaller (this);
160 CheckComRCReturnRC (autoCaller.rc());
161
162 mInterfaceName.cloneTo (aInterfaceName);
163
164 return S_OK;
165}
166
167/**
168 * Returns the GUID of the host network interface.
169 *
170 * @returns COM status code
171 * @param aGuid address of result pointer
172 */
173STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
174{
175 CheckComArgOutPointerValid(aGuid);
176
177 AutoCaller autoCaller (this);
178 CheckComRCReturnRC (autoCaller.rc());
179
180 mGuid.cloneTo (aGuid);
181
182 return S_OK;
183}
184
185
186/**
187 * Returns the IP address of the host network interface.
188 *
189 * @returns COM status code
190 * @param aIPAddress address of result pointer
191 */
192STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
193{
194 CheckComArgOutPointerValid(aIPAddress);
195
196 AutoCaller autoCaller (this);
197 CheckComRCReturnRC (autoCaller.rc());
198
199 *aIPAddress = m.IPAddress;
200
201 return S_OK;
202}
203
204/**
205 * Returns the netwok mask of the host network interface.
206 *
207 * @returns COM status code
208 * @param aNetworkMask address of result pointer
209 */
210STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
211{
212 CheckComArgOutPointerValid(aNetworkMask);
213
214 AutoCaller autoCaller (this);
215 CheckComRCReturnRC (autoCaller.rc());
216
217 *aNetworkMask = m.networkMask;
218
219 return S_OK;
220}
221
222STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Supported) (BOOL *aIPV6Supported)
223{
224 CheckComArgOutPointerValid(aIPV6Supported);
225
226 *aIPV6Supported = TRUE;
227
228 return S_OK;
229}
230
231/**
232 * Returns the IP V6 address of the host network interface.
233 *
234 * @returns COM status code
235 * @param aIPV6Address address of result pointer
236 */
237STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
238{
239 CheckComArgOutPointerValid(aIPV6Address);
240
241 AutoCaller autoCaller (this);
242 CheckComRCReturnRC (autoCaller.rc());
243
244 m.IPV6Address.cloneTo (aIPV6Address);
245
246 return S_OK;
247}
248
249/**
250 * Returns the IP V6 network mask of the host network interface.
251 *
252 * @returns COM status code
253 * @param aIPV6Mask address of result pointer
254 */
255STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMaskPrefixLength) (ULONG *aIPV6NetworkMaskPrefixLength)
256{
257 CheckComArgOutPointerValid(aIPV6NetworkMaskPrefixLength);
258
259 AutoCaller autoCaller (this);
260 CheckComRCReturnRC (autoCaller.rc());
261
262 *aIPV6NetworkMaskPrefixLength = m.IPV6NetworkMaskPrefixLength;
263
264 return S_OK;
265}
266
267/**
268 * Returns the hardware address of the host network interface.
269 *
270 * @returns COM status code
271 * @param aHardwareAddress address of result pointer
272 */
273STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
274{
275 CheckComArgOutPointerValid(aHardwareAddress);
276
277 AutoCaller autoCaller (this);
278 CheckComRCReturnRC (autoCaller.rc());
279
280 m.hardwareAddress.cloneTo (aHardwareAddress);
281
282 return S_OK;
283}
284
285/**
286 * Returns the encapsulation protocol type of the host network interface.
287 *
288 * @returns COM status code
289 * @param aType address of result pointer
290 */
291STDMETHODIMP HostNetworkInterface::COMGETTER(MediumType) (HostNetworkInterfaceMediumType_T *aType)
292{
293 CheckComArgOutPointerValid(aType);
294
295 AutoCaller autoCaller (this);
296 CheckComRCReturnRC (autoCaller.rc());
297
298 *aType = m.mediumType;
299
300 return S_OK;
301}
302
303/**
304 * Returns the current state of the host network interface.
305 *
306 * @returns COM status code
307 * @param aStatus address of result pointer
308 */
309STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
310{
311 CheckComArgOutPointerValid(aStatus);
312
313 AutoCaller autoCaller (this);
314 CheckComRCReturnRC (autoCaller.rc());
315
316 *aStatus = m.status;
317
318 return S_OK;
319}
320
321/**
322 * Returns network interface type
323 *
324 * @returns COM status code
325 * @param aType address of result pointer
326 */
327STDMETHODIMP HostNetworkInterface::COMGETTER(InterfaceType) (HostNetworkInterfaceType_T *aType)
328{
329 CheckComArgOutPointerValid(aType);
330
331 AutoCaller autoCaller (this);
332 CheckComRCReturnRC (autoCaller.rc());
333
334 *aType = mIfType;
335
336 return S_OK;
337
338}
339
340STDMETHODIMP HostNetworkInterface::EnableStaticIpConfig (ULONG aIPAddress, ULONG aNetworkMask)
341{
342#ifndef VBOX_WITH_HOSTNETIF_API
343 return E_NOTIMPL;
344#else
345 AutoCaller autoCaller (this);
346 CheckComRCReturnRC (autoCaller.rc());
347
348 int rc = NetIfEnableStaticIpConfig(this, aIPAddress, aNetworkMask);
349 if (RT_FAILURE(rc))
350 {
351 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
352 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
353 }
354 return S_OK;
355#endif
356}
357
358STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
359{
360#ifndef VBOX_WITH_HOSTNETIF_API
361 return E_NOTIMPL;
362#else
363 if (!aIPV6Address)
364 return E_INVALIDARG;
365 if (aIPV6MaskPrefixLength > 128)
366 return E_INVALIDARG;
367
368 AutoCaller autoCaller (this);
369 CheckComRCReturnRC (autoCaller.rc());
370
371 int rc = NetIfEnableStaticIpConfigV6(this, aIPV6Address, aIPV6MaskPrefixLength);
372 if (RT_FAILURE(rc))
373 {
374 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
375 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
376 }
377 return S_OK;
378#endif
379}
380
381STDMETHODIMP HostNetworkInterface::EnableDynamicIpConfig ()
382{
383#ifndef VBOX_WITH_HOSTNETIF_API
384 return E_NOTIMPL;
385#else
386 AutoCaller autoCaller (this);
387 CheckComRCReturnRC (autoCaller.rc());
388
389 int rc = NetIfEnableDynamicIpConfig(this);
390 if (RT_FAILURE(rc))
391 {
392 LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
393 return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
394 }
395 return S_OK;
396#endif
397}
398
399HRESULT HostNetworkInterface::setVirtualBox(VirtualBox *pVBox)
400{
401 AutoCaller autoCaller (this);
402 CheckComRCReturnRC (autoCaller.rc());
403 mVBox = pVBox;
404
405 return S_OK;
406}
407
408HRESULT HostNetworkInterface::getVirtualBox(VirtualBox **ppVBox)
409{
410 AutoCaller autoCaller (this);
411 CheckComRCReturnRC (autoCaller.rc());
412
413 if (!ppVBox)
414 return E_INVALIDARG;
415
416 *ppVBox = mVBox;
417 return S_OK;
418}
419
420/* 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