VirtualBox

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

Last change on this file since 16524 was 15511, checked in by vboxsync, 16 years ago

#3282: Fix for non-Windows builds.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: HostNetworkInterfaceImpl.cpp 15511 2008-12-15 15:38:07Z 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)
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
68 /* Confirm a successful initialization */
69 autoInitSpan.setSucceeded();
70
71 return S_OK;
72}
73
74#ifdef VBOX_WITH_HOSTNETIF_API
75static Bstr composeIPv6Address(PRTNETADDRIPV6 aAddrPtr)
76{
77 char szTmp[8*5];
78
79 RTStrPrintf(szTmp, sizeof(szTmp),
80 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
81 "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
82 aAddrPtr->au8[0], aAddrPtr->au8[1],
83 aAddrPtr->au8[2], aAddrPtr->au8[3],
84 aAddrPtr->au8[4], aAddrPtr->au8[5],
85 aAddrPtr->au8[6], aAddrPtr->au8[7],
86 aAddrPtr->au8[8], aAddrPtr->au8[9],
87 aAddrPtr->au8[10], aAddrPtr->au8[11],
88 aAddrPtr->au8[12], aAddrPtr->au8[13],
89 aAddrPtr->au8[14], aAddrPtr->au8[15]);
90 return Bstr(szTmp);
91}
92
93static Bstr composeHardwareAddress(PRTMAC aMacPtr)
94{
95 char szTmp[6*3];
96
97 RTStrPrintf(szTmp, sizeof(szTmp),
98 "%02x:%02x:%02x:%02x:%02x:%02x",
99 aMacPtr->au8[0], aMacPtr->au8[1],
100 aMacPtr->au8[2], aMacPtr->au8[3],
101 aMacPtr->au8[4], aMacPtr->au8[5]);
102 return Bstr(szTmp);
103}
104
105/**
106 * Initializes the host object.
107 *
108 * @returns COM result indicator
109 * @param aInterfaceName name of the network interface
110 * @param aGuid GUID of the host network interface
111 */
112HRESULT HostNetworkInterface::init (Bstr aInterfaceName, PNETIFINFO pIf)
113{
114// LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
115// aInterfaceName.raw(), aGuid.toString().raw()));
116
117// ComAssertRet (aInterfaceName, E_INVALIDARG);
118// ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
119 ComAssertRet (pIf, E_INVALIDARG);
120
121 /* Enclose the state transition NotReady->InInit->Ready */
122 AutoInitSpan autoInitSpan (this);
123 AssertReturn (autoInitSpan.isOk(), E_FAIL);
124
125 unconst (mInterfaceName) = aInterfaceName;
126 unconst (mGuid) = pIf->Uuid;
127 m.IPAddress = pIf->IPAddress.u;
128 m.networkMask = pIf->IPNetMask.u;
129 m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
130 m.IPV6NetworkMask = composeIPv6Address(&pIf->IPv6NetMask);
131 m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
132#ifdef RT_OS_WINDOWS
133 m.type = (HostNetworkInterfaceType)pIf->enmType;
134 m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
135#else /* !RT_OS_WINDOWS */
136 m.type = pIf->enmType;
137 m.status = pIf->enmStatus;
138#endif /* !RT_OS_WINDOWS */
139
140 /* Confirm a successful initialization */
141 autoInitSpan.setSucceeded();
142
143 return S_OK;
144}
145#endif
146
147// IHostNetworkInterface properties
148/////////////////////////////////////////////////////////////////////////////
149
150/**
151 * Returns the name of the host network interface.
152 *
153 * @returns COM status code
154 * @param aInterfaceName address of result pointer
155 */
156STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
157{
158 CheckComArgOutPointerValid(aInterfaceName);
159
160 AutoCaller autoCaller (this);
161 CheckComRCReturnRC (autoCaller.rc());
162
163 mInterfaceName.cloneTo (aInterfaceName);
164
165 return S_OK;
166}
167
168/**
169 * Returns the GUID of the host network interface.
170 *
171 * @returns COM status code
172 * @param aGuid address of result pointer
173 */
174STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
175{
176 CheckComArgOutPointerValid(aGuid);
177
178 AutoCaller autoCaller (this);
179 CheckComRCReturnRC (autoCaller.rc());
180
181 mGuid.cloneTo (aGuid);
182
183 return S_OK;
184}
185
186
187/**
188 * Returns the IP address of the host network interface.
189 *
190 * @returns COM status code
191 * @param aIPAddress address of result pointer
192 */
193STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
194{
195 CheckComArgOutPointerValid(aIPAddress);
196
197 AutoCaller autoCaller (this);
198 CheckComRCReturnRC (autoCaller.rc());
199
200 *aIPAddress = m.IPAddress;
201
202 return S_OK;
203}
204
205/**
206 * Returns the netwok mask of the host network interface.
207 *
208 * @returns COM status code
209 * @param aNetworkMask address of result pointer
210 */
211STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
212{
213 CheckComArgOutPointerValid(aNetworkMask);
214
215 AutoCaller autoCaller (this);
216 CheckComRCReturnRC (autoCaller.rc());
217
218 *aNetworkMask = m.networkMask;
219
220 return S_OK;
221}
222
223/**
224 * Returns the IP V6 address of the host network interface.
225 *
226 * @returns COM status code
227 * @param aIPV6Address address of result pointer
228 */
229STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
230{
231 CheckComArgOutPointerValid(aIPV6Address);
232
233 AutoCaller autoCaller (this);
234 CheckComRCReturnRC (autoCaller.rc());
235
236 m.IPV6Address.cloneTo (aIPV6Address);
237
238 return S_OK;
239}
240
241/**
242 * Returns the IP V6 network mask of the host network interface.
243 *
244 * @returns COM status code
245 * @param aIPV6Mask address of result pointer
246 */
247STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMask) (BSTR *aIPV6Mask)
248{
249 CheckComArgOutPointerValid(aIPV6Mask);
250
251 AutoCaller autoCaller (this);
252 CheckComRCReturnRC (autoCaller.rc());
253
254 m.IPV6NetworkMask.cloneTo (aIPV6Mask);
255
256 return S_OK;
257}
258
259/**
260 * Returns the hardware address of the host network interface.
261 *
262 * @returns COM status code
263 * @param aHardwareAddress address of result pointer
264 */
265STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
266{
267 CheckComArgOutPointerValid(aHardwareAddress);
268
269 AutoCaller autoCaller (this);
270 CheckComRCReturnRC (autoCaller.rc());
271
272 m.hardwareAddress.cloneTo (aHardwareAddress);
273
274 return S_OK;
275}
276
277/**
278 * Returns the encapsulation protocol type of the host network interface.
279 *
280 * @returns COM status code
281 * @param aType address of result pointer
282 */
283STDMETHODIMP HostNetworkInterface::COMGETTER(Type) (HostNetworkInterfaceType_T *aType)
284{
285 CheckComArgOutPointerValid(aType);
286
287 AutoCaller autoCaller (this);
288 CheckComRCReturnRC (autoCaller.rc());
289
290 *aType = m.type;
291
292 return S_OK;
293}
294
295/**
296 * Returns the current state of the host network interface.
297 *
298 * @returns COM status code
299 * @param aStatus address of result pointer
300 */
301STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
302{
303 CheckComArgOutPointerValid(aStatus);
304
305 AutoCaller autoCaller (this);
306 CheckComRCReturnRC (autoCaller.rc());
307
308 *aStatus = m.status;
309
310 return S_OK;
311}
312
313/* 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