1 | /* $Id: HostNetworkInterfaceImpl.cpp 17333 2009-03-04 09:14:29Z 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 |
|
---|
31 | DEFINE_EMPTY_CTOR_DTOR (HostNetworkInterface)
|
---|
32 |
|
---|
33 | HRESULT HostNetworkInterface::FinalConstruct()
|
---|
34 | {
|
---|
35 | return S_OK;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void 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 | */
|
---|
53 | HRESULT 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 | static Bstr composeIPv6Address(PRTNETADDRIPV6 aAddrPtr)
|
---|
78 | {
|
---|
79 | char szTmp[8*5];
|
---|
80 |
|
---|
81 | RTStrPrintf(szTmp, sizeof(szTmp),
|
---|
82 | "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
|
---|
83 | "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
---|
84 | aAddrPtr->au8[0], aAddrPtr->au8[1],
|
---|
85 | aAddrPtr->au8[2], aAddrPtr->au8[3],
|
---|
86 | aAddrPtr->au8[4], aAddrPtr->au8[5],
|
---|
87 | aAddrPtr->au8[6], aAddrPtr->au8[7],
|
---|
88 | aAddrPtr->au8[8], aAddrPtr->au8[9],
|
---|
89 | aAddrPtr->au8[10], aAddrPtr->au8[11],
|
---|
90 | aAddrPtr->au8[12], aAddrPtr->au8[13],
|
---|
91 | aAddrPtr->au8[14], aAddrPtr->au8[15]);
|
---|
92 | return Bstr(szTmp);
|
---|
93 | }
|
---|
94 |
|
---|
95 | static Bstr composeHardwareAddress(PRTMAC aMacPtr)
|
---|
96 | {
|
---|
97 | char szTmp[6*3];
|
---|
98 |
|
---|
99 | RTStrPrintf(szTmp, sizeof(szTmp),
|
---|
100 | "%02x:%02x:%02x:%02x:%02x:%02x",
|
---|
101 | aMacPtr->au8[0], aMacPtr->au8[1],
|
---|
102 | aMacPtr->au8[2], aMacPtr->au8[3],
|
---|
103 | aMacPtr->au8[4], aMacPtr->au8[5]);
|
---|
104 | return Bstr(szTmp);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Initializes the host object.
|
---|
109 | *
|
---|
110 | * @returns COM result indicator
|
---|
111 | * @param aInterfaceName name of the network interface
|
---|
112 | * @param aGuid GUID of the host network interface
|
---|
113 | */
|
---|
114 | HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
|
---|
115 | {
|
---|
116 | // LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
|
---|
117 | // aInterfaceName.raw(), aGuid.toString().raw()));
|
---|
118 |
|
---|
119 | // ComAssertRet (aInterfaceName, E_INVALIDARG);
|
---|
120 | // ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
|
---|
121 | ComAssertRet (pIf, E_INVALIDARG);
|
---|
122 |
|
---|
123 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
124 | AutoInitSpan autoInitSpan (this);
|
---|
125 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
126 |
|
---|
127 | unconst (mInterfaceName) = aInterfaceName;
|
---|
128 | unconst (mGuid) = pIf->Uuid;
|
---|
129 | mIfType = ifType;
|
---|
130 |
|
---|
131 | m.IPAddress = pIf->IPAddress.u;
|
---|
132 | m.networkMask = pIf->IPNetMask.u;
|
---|
133 | m.defaultGateway = pIf->IPDefaultGateway.u;
|
---|
134 | m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
|
---|
135 | m.IPV6NetworkMask = composeIPv6Address(&pIf->IPv6NetMask);
|
---|
136 | m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
|
---|
137 | #ifdef RT_OS_WINDOWS
|
---|
138 | m.mediumType = (HostNetworkInterfaceMediumType)pIf->enmMediumType;
|
---|
139 | m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
|
---|
140 | #else /* !RT_OS_WINDOWS */
|
---|
141 | m.mediumType = pIf->enmMediumType;
|
---|
142 | m.status = pIf->enmStatus;
|
---|
143 | #endif /* !RT_OS_WINDOWS */
|
---|
144 |
|
---|
145 | /* Confirm a successful initialization */
|
---|
146 | autoInitSpan.setSucceeded();
|
---|
147 |
|
---|
148 | return S_OK;
|
---|
149 | }
|
---|
150 | #endif
|
---|
151 |
|
---|
152 | // IHostNetworkInterface properties
|
---|
153 | /////////////////////////////////////////////////////////////////////////////
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Returns the name of the host network interface.
|
---|
157 | *
|
---|
158 | * @returns COM status code
|
---|
159 | * @param aInterfaceName address of result pointer
|
---|
160 | */
|
---|
161 | STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
|
---|
162 | {
|
---|
163 | CheckComArgOutPointerValid(aInterfaceName);
|
---|
164 |
|
---|
165 | AutoCaller autoCaller (this);
|
---|
166 | CheckComRCReturnRC (autoCaller.rc());
|
---|
167 |
|
---|
168 | mInterfaceName.cloneTo (aInterfaceName);
|
---|
169 |
|
---|
170 | return S_OK;
|
---|
171 | }
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Returns the GUID of the host network interface.
|
---|
175 | *
|
---|
176 | * @returns COM status code
|
---|
177 | * @param aGuid address of result pointer
|
---|
178 | */
|
---|
179 | STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
|
---|
180 | {
|
---|
181 | CheckComArgOutPointerValid(aGuid);
|
---|
182 |
|
---|
183 | AutoCaller autoCaller (this);
|
---|
184 | CheckComRCReturnRC (autoCaller.rc());
|
---|
185 |
|
---|
186 | mGuid.cloneTo (aGuid);
|
---|
187 |
|
---|
188 | return S_OK;
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Returns the IP address of the host network interface.
|
---|
194 | *
|
---|
195 | * @returns COM status code
|
---|
196 | * @param aIPAddress address of result pointer
|
---|
197 | */
|
---|
198 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
|
---|
199 | {
|
---|
200 | CheckComArgOutPointerValid(aIPAddress);
|
---|
201 |
|
---|
202 | AutoCaller autoCaller (this);
|
---|
203 | CheckComRCReturnRC (autoCaller.rc());
|
---|
204 |
|
---|
205 | *aIPAddress = m.IPAddress;
|
---|
206 |
|
---|
207 | return S_OK;
|
---|
208 | }
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Returns the netwok mask of the host network interface.
|
---|
212 | *
|
---|
213 | * @returns COM status code
|
---|
214 | * @param aNetworkMask address of result pointer
|
---|
215 | */
|
---|
216 | STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
|
---|
217 | {
|
---|
218 | CheckComArgOutPointerValid(aNetworkMask);
|
---|
219 |
|
---|
220 | AutoCaller autoCaller (this);
|
---|
221 | CheckComRCReturnRC (autoCaller.rc());
|
---|
222 |
|
---|
223 | *aNetworkMask = m.networkMask;
|
---|
224 |
|
---|
225 | return S_OK;
|
---|
226 | }
|
---|
227 |
|
---|
228 | /**
|
---|
229 | * Returns the default gateway of the host network interface.
|
---|
230 | *
|
---|
231 | * @returns COM status code
|
---|
232 | * @param aNetworkMask address of result pointer
|
---|
233 | */
|
---|
234 | STDMETHODIMP HostNetworkInterface::COMGETTER(DefaultGateway) (ULONG *aDefaultGateway)
|
---|
235 | {
|
---|
236 | CheckComArgOutPointerValid(aDefaultGateway);
|
---|
237 |
|
---|
238 | AutoCaller autoCaller (this);
|
---|
239 | CheckComRCReturnRC (autoCaller.rc());
|
---|
240 |
|
---|
241 | *aDefaultGateway = m.defaultGateway;
|
---|
242 |
|
---|
243 | return S_OK;
|
---|
244 | }
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Returns the IP V6 address of the host network interface.
|
---|
248 | *
|
---|
249 | * @returns COM status code
|
---|
250 | * @param aIPV6Address address of result pointer
|
---|
251 | */
|
---|
252 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
|
---|
253 | {
|
---|
254 | CheckComArgOutPointerValid(aIPV6Address);
|
---|
255 |
|
---|
256 | AutoCaller autoCaller (this);
|
---|
257 | CheckComRCReturnRC (autoCaller.rc());
|
---|
258 |
|
---|
259 | m.IPV6Address.cloneTo (aIPV6Address);
|
---|
260 |
|
---|
261 | return S_OK;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Returns the IP V6 network mask of the host network interface.
|
---|
266 | *
|
---|
267 | * @returns COM status code
|
---|
268 | * @param aIPV6Mask address of result pointer
|
---|
269 | */
|
---|
270 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMask) (BSTR *aIPV6Mask)
|
---|
271 | {
|
---|
272 | CheckComArgOutPointerValid(aIPV6Mask);
|
---|
273 |
|
---|
274 | AutoCaller autoCaller (this);
|
---|
275 | CheckComRCReturnRC (autoCaller.rc());
|
---|
276 |
|
---|
277 | m.IPV6NetworkMask.cloneTo (aIPV6Mask);
|
---|
278 |
|
---|
279 | return S_OK;
|
---|
280 | }
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Returns the hardware address of the host network interface.
|
---|
284 | *
|
---|
285 | * @returns COM status code
|
---|
286 | * @param aHardwareAddress address of result pointer
|
---|
287 | */
|
---|
288 | STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
|
---|
289 | {
|
---|
290 | CheckComArgOutPointerValid(aHardwareAddress);
|
---|
291 |
|
---|
292 | AutoCaller autoCaller (this);
|
---|
293 | CheckComRCReturnRC (autoCaller.rc());
|
---|
294 |
|
---|
295 | m.hardwareAddress.cloneTo (aHardwareAddress);
|
---|
296 |
|
---|
297 | return S_OK;
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Returns the encapsulation protocol type of the host network interface.
|
---|
302 | *
|
---|
303 | * @returns COM status code
|
---|
304 | * @param aType address of result pointer
|
---|
305 | */
|
---|
306 | STDMETHODIMP HostNetworkInterface::COMGETTER(MediumType) (HostNetworkInterfaceMediumType_T *aType)
|
---|
307 | {
|
---|
308 | CheckComArgOutPointerValid(aType);
|
---|
309 |
|
---|
310 | AutoCaller autoCaller (this);
|
---|
311 | CheckComRCReturnRC (autoCaller.rc());
|
---|
312 |
|
---|
313 | *aType = m.mediumType;
|
---|
314 |
|
---|
315 | return S_OK;
|
---|
316 | }
|
---|
317 |
|
---|
318 | /**
|
---|
319 | * Returns the current state of the host network interface.
|
---|
320 | *
|
---|
321 | * @returns COM status code
|
---|
322 | * @param aStatus address of result pointer
|
---|
323 | */
|
---|
324 | STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
|
---|
325 | {
|
---|
326 | CheckComArgOutPointerValid(aStatus);
|
---|
327 |
|
---|
328 | AutoCaller autoCaller (this);
|
---|
329 | CheckComRCReturnRC (autoCaller.rc());
|
---|
330 |
|
---|
331 | *aStatus = m.status;
|
---|
332 |
|
---|
333 | return S_OK;
|
---|
334 | }
|
---|
335 |
|
---|
336 | /**
|
---|
337 | * Returns network interface type
|
---|
338 | *
|
---|
339 | * @returns COM status code
|
---|
340 | * @param aType address of result pointer
|
---|
341 | */
|
---|
342 | STDMETHODIMP HostNetworkInterface::COMGETTER(InterfaceType) (HostNetworkInterfaceType_T *aType)
|
---|
343 | {
|
---|
344 | CheckComArgOutPointerValid(aType);
|
---|
345 |
|
---|
346 | AutoCaller autoCaller (this);
|
---|
347 | CheckComRCReturnRC (autoCaller.rc());
|
---|
348 |
|
---|
349 | *aType = mIfType;
|
---|
350 |
|
---|
351 | return S_OK;
|
---|
352 |
|
---|
353 | }
|
---|
354 |
|
---|
355 | STDMETHODIMP HostNetworkInterface::EnableStaticIpConfig (ULONG aIPAddress, ULONG aNetworkMask, ULONG aDefaultGateway)
|
---|
356 | {
|
---|
357 | return E_NOTIMPL;
|
---|
358 | }
|
---|
359 |
|
---|
360 | STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (BSTR aIPV6Address, BSTR aIPV6Mask)
|
---|
361 | {
|
---|
362 | return E_NOTIMPL;
|
---|
363 | }
|
---|
364 |
|
---|
365 | STDMETHODIMP HostNetworkInterface::EnableDynamicIpConfig ()
|
---|
366 | {
|
---|
367 | return E_NOTIMPL;
|
---|
368 | }
|
---|
369 |
|
---|
370 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|