1 | /* $Id: HostNetworkInterfaceImpl.cpp 16967 2009-02-20 10:03:55Z 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, BOOL aReal)
|
---|
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 | mReal = aReal;
|
---|
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, BOOL aReal, 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 | mReal = aReal;
|
---|
130 |
|
---|
131 | m.IPAddress = pIf->IPAddress.u;
|
---|
132 | m.networkMask = pIf->IPNetMask.u;
|
---|
133 | m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
|
---|
134 | m.IPV6NetworkMask = composeIPv6Address(&pIf->IPv6NetMask);
|
---|
135 | m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
|
---|
136 | #ifdef RT_OS_WINDOWS
|
---|
137 | m.type = (HostNetworkInterfaceType)pIf->enmType;
|
---|
138 | m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
|
---|
139 | #else /* !RT_OS_WINDOWS */
|
---|
140 | m.type = pIf->enmType;
|
---|
141 | m.status = pIf->enmStatus;
|
---|
142 | #endif /* !RT_OS_WINDOWS */
|
---|
143 |
|
---|
144 | /* Confirm a successful initialization */
|
---|
145 | autoInitSpan.setSucceeded();
|
---|
146 |
|
---|
147 | return S_OK;
|
---|
148 | }
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | // IHostNetworkInterface properties
|
---|
152 | /////////////////////////////////////////////////////////////////////////////
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Returns the name of the host network interface.
|
---|
156 | *
|
---|
157 | * @returns COM status code
|
---|
158 | * @param aInterfaceName address of result pointer
|
---|
159 | */
|
---|
160 | STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
|
---|
161 | {
|
---|
162 | CheckComArgOutPointerValid(aInterfaceName);
|
---|
163 |
|
---|
164 | AutoCaller autoCaller (this);
|
---|
165 | CheckComRCReturnRC (autoCaller.rc());
|
---|
166 |
|
---|
167 | mInterfaceName.cloneTo (aInterfaceName);
|
---|
168 |
|
---|
169 | return S_OK;
|
---|
170 | }
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Returns the GUID of the host network interface.
|
---|
174 | *
|
---|
175 | * @returns COM status code
|
---|
176 | * @param aGuid address of result pointer
|
---|
177 | */
|
---|
178 | STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
|
---|
179 | {
|
---|
180 | CheckComArgOutPointerValid(aGuid);
|
---|
181 |
|
---|
182 | AutoCaller autoCaller (this);
|
---|
183 | CheckComRCReturnRC (autoCaller.rc());
|
---|
184 |
|
---|
185 | mGuid.cloneTo (aGuid);
|
---|
186 |
|
---|
187 | return S_OK;
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Returns the IP address of the host network interface.
|
---|
193 | *
|
---|
194 | * @returns COM status code
|
---|
195 | * @param aIPAddress address of result pointer
|
---|
196 | */
|
---|
197 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
|
---|
198 | {
|
---|
199 | CheckComArgOutPointerValid(aIPAddress);
|
---|
200 |
|
---|
201 | AutoCaller autoCaller (this);
|
---|
202 | CheckComRCReturnRC (autoCaller.rc());
|
---|
203 |
|
---|
204 | *aIPAddress = m.IPAddress;
|
---|
205 |
|
---|
206 | return S_OK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Returns the netwok mask of the host network interface.
|
---|
211 | *
|
---|
212 | * @returns COM status code
|
---|
213 | * @param aNetworkMask address of result pointer
|
---|
214 | */
|
---|
215 | STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
|
---|
216 | {
|
---|
217 | CheckComArgOutPointerValid(aNetworkMask);
|
---|
218 |
|
---|
219 | AutoCaller autoCaller (this);
|
---|
220 | CheckComRCReturnRC (autoCaller.rc());
|
---|
221 |
|
---|
222 | *aNetworkMask = m.networkMask;
|
---|
223 |
|
---|
224 | return S_OK;
|
---|
225 | }
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Returns the IP V6 address of the host network interface.
|
---|
229 | *
|
---|
230 | * @returns COM status code
|
---|
231 | * @param aIPV6Address address of result pointer
|
---|
232 | */
|
---|
233 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
|
---|
234 | {
|
---|
235 | CheckComArgOutPointerValid(aIPV6Address);
|
---|
236 |
|
---|
237 | AutoCaller autoCaller (this);
|
---|
238 | CheckComRCReturnRC (autoCaller.rc());
|
---|
239 |
|
---|
240 | m.IPV6Address.cloneTo (aIPV6Address);
|
---|
241 |
|
---|
242 | return S_OK;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Returns the IP V6 network mask of the host network interface.
|
---|
247 | *
|
---|
248 | * @returns COM status code
|
---|
249 | * @param aIPV6Mask address of result pointer
|
---|
250 | */
|
---|
251 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMask) (BSTR *aIPV6Mask)
|
---|
252 | {
|
---|
253 | CheckComArgOutPointerValid(aIPV6Mask);
|
---|
254 |
|
---|
255 | AutoCaller autoCaller (this);
|
---|
256 | CheckComRCReturnRC (autoCaller.rc());
|
---|
257 |
|
---|
258 | m.IPV6NetworkMask.cloneTo (aIPV6Mask);
|
---|
259 |
|
---|
260 | return S_OK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Returns the hardware address of the host network interface.
|
---|
265 | *
|
---|
266 | * @returns COM status code
|
---|
267 | * @param aHardwareAddress address of result pointer
|
---|
268 | */
|
---|
269 | STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
|
---|
270 | {
|
---|
271 | CheckComArgOutPointerValid(aHardwareAddress);
|
---|
272 |
|
---|
273 | AutoCaller autoCaller (this);
|
---|
274 | CheckComRCReturnRC (autoCaller.rc());
|
---|
275 |
|
---|
276 | m.hardwareAddress.cloneTo (aHardwareAddress);
|
---|
277 |
|
---|
278 | return S_OK;
|
---|
279 | }
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Returns the encapsulation protocol type of the host network interface.
|
---|
283 | *
|
---|
284 | * @returns COM status code
|
---|
285 | * @param aType address of result pointer
|
---|
286 | */
|
---|
287 | STDMETHODIMP HostNetworkInterface::COMGETTER(Type) (HostNetworkInterfaceType_T *aType)
|
---|
288 | {
|
---|
289 | CheckComArgOutPointerValid(aType);
|
---|
290 |
|
---|
291 | AutoCaller autoCaller (this);
|
---|
292 | CheckComRCReturnRC (autoCaller.rc());
|
---|
293 |
|
---|
294 | *aType = m.type;
|
---|
295 |
|
---|
296 | return S_OK;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Returns the current state of the host network interface.
|
---|
301 | *
|
---|
302 | * @returns COM status code
|
---|
303 | * @param aStatus address of result pointer
|
---|
304 | */
|
---|
305 | STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
|
---|
306 | {
|
---|
307 | CheckComArgOutPointerValid(aStatus);
|
---|
308 |
|
---|
309 | AutoCaller autoCaller (this);
|
---|
310 | CheckComRCReturnRC (autoCaller.rc());
|
---|
311 |
|
---|
312 | *aStatus = m.status;
|
---|
313 |
|
---|
314 | return S_OK;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Returns true if this is a "real" adapter, false if this is a Virtualbox Host Adapter
|
---|
319 | *
|
---|
320 | * @returns COM status code
|
---|
321 | * @param aReal address of result pointer
|
---|
322 | */
|
---|
323 | STDMETHODIMP HostNetworkInterface::COMGETTER(Real) (BOOL *aReal)
|
---|
324 | {
|
---|
325 | CheckComArgOutPointerValid(aReal);
|
---|
326 |
|
---|
327 | AutoCaller autoCaller (this);
|
---|
328 | CheckComRCReturnRC (autoCaller.rc());
|
---|
329 |
|
---|
330 | *aReal = mReal;
|
---|
331 |
|
---|
332 | return S_OK;
|
---|
333 |
|
---|
334 | }
|
---|
335 |
|
---|
336 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|