1 | /* $Id: HostNetworkInterfaceImpl.cpp 15442 2008-12-13 13:40: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 |
|
---|
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)
|
---|
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
|
---|
75 | static 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 |
|
---|
93 | static 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 | */
|
---|
112 | HRESULT 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 | m.type = pIf->enmType;
|
---|
133 | m.status = pIf->enmStatus;
|
---|
134 |
|
---|
135 | /* Confirm a successful initialization */
|
---|
136 | autoInitSpan.setSucceeded();
|
---|
137 |
|
---|
138 | return S_OK;
|
---|
139 | }
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | // IHostNetworkInterface properties
|
---|
143 | /////////////////////////////////////////////////////////////////////////////
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Returns the name of the host network interface.
|
---|
147 | *
|
---|
148 | * @returns COM status code
|
---|
149 | * @param aInterfaceName address of result pointer
|
---|
150 | */
|
---|
151 | STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
|
---|
152 | {
|
---|
153 | CheckComArgOutPointerValid(aInterfaceName);
|
---|
154 |
|
---|
155 | AutoCaller autoCaller (this);
|
---|
156 | CheckComRCReturnRC (autoCaller.rc());
|
---|
157 |
|
---|
158 | mInterfaceName.cloneTo (aInterfaceName);
|
---|
159 |
|
---|
160 | return S_OK;
|
---|
161 | }
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Returns the GUID of the host network interface.
|
---|
165 | *
|
---|
166 | * @returns COM status code
|
---|
167 | * @param aGuid address of result pointer
|
---|
168 | */
|
---|
169 | STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
|
---|
170 | {
|
---|
171 | CheckComArgOutPointerValid(aGuid);
|
---|
172 |
|
---|
173 | AutoCaller autoCaller (this);
|
---|
174 | CheckComRCReturnRC (autoCaller.rc());
|
---|
175 |
|
---|
176 | mGuid.cloneTo (aGuid);
|
---|
177 |
|
---|
178 | return S_OK;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Returns the IP address of the host network interface.
|
---|
184 | *
|
---|
185 | * @returns COM status code
|
---|
186 | * @param aIPAddress address of result pointer
|
---|
187 | */
|
---|
188 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
|
---|
189 | {
|
---|
190 | CheckComArgOutPointerValid(aIPAddress);
|
---|
191 |
|
---|
192 | AutoCaller autoCaller (this);
|
---|
193 | CheckComRCReturnRC (autoCaller.rc());
|
---|
194 |
|
---|
195 | *aIPAddress = m.IPAddress;
|
---|
196 |
|
---|
197 | return S_OK;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Returns the netwok mask of the host network interface.
|
---|
202 | *
|
---|
203 | * @returns COM status code
|
---|
204 | * @param aNetworkMask address of result pointer
|
---|
205 | */
|
---|
206 | STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
|
---|
207 | {
|
---|
208 | CheckComArgOutPointerValid(aNetworkMask);
|
---|
209 |
|
---|
210 | AutoCaller autoCaller (this);
|
---|
211 | CheckComRCReturnRC (autoCaller.rc());
|
---|
212 |
|
---|
213 | *aNetworkMask = m.networkMask;
|
---|
214 |
|
---|
215 | return S_OK;
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Returns the IP V6 address of the host network interface.
|
---|
220 | *
|
---|
221 | * @returns COM status code
|
---|
222 | * @param aIPV6Address address of result pointer
|
---|
223 | */
|
---|
224 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
|
---|
225 | {
|
---|
226 | CheckComArgOutPointerValid(aIPV6Address);
|
---|
227 |
|
---|
228 | AutoCaller autoCaller (this);
|
---|
229 | CheckComRCReturnRC (autoCaller.rc());
|
---|
230 |
|
---|
231 | m.IPV6Address.cloneTo (aIPV6Address);
|
---|
232 |
|
---|
233 | return S_OK;
|
---|
234 | }
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Returns the IP V6 network mask of the host network interface.
|
---|
238 | *
|
---|
239 | * @returns COM status code
|
---|
240 | * @param aIPV6Mask address of result pointer
|
---|
241 | */
|
---|
242 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMask) (BSTR *aIPV6Mask)
|
---|
243 | {
|
---|
244 | CheckComArgOutPointerValid(aIPV6Mask);
|
---|
245 |
|
---|
246 | AutoCaller autoCaller (this);
|
---|
247 | CheckComRCReturnRC (autoCaller.rc());
|
---|
248 |
|
---|
249 | m.IPV6NetworkMask.cloneTo (aIPV6Mask);
|
---|
250 |
|
---|
251 | return S_OK;
|
---|
252 | }
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Returns the hardware address of the host network interface.
|
---|
256 | *
|
---|
257 | * @returns COM status code
|
---|
258 | * @param aHardwareAddress address of result pointer
|
---|
259 | */
|
---|
260 | STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
|
---|
261 | {
|
---|
262 | CheckComArgOutPointerValid(aHardwareAddress);
|
---|
263 |
|
---|
264 | AutoCaller autoCaller (this);
|
---|
265 | CheckComRCReturnRC (autoCaller.rc());
|
---|
266 |
|
---|
267 | m.hardwareAddress.cloneTo (aHardwareAddress);
|
---|
268 |
|
---|
269 | return S_OK;
|
---|
270 | }
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Returns the encapsulation protocol type of the host network interface.
|
---|
274 | *
|
---|
275 | * @returns COM status code
|
---|
276 | * @param aType address of result pointer
|
---|
277 | */
|
---|
278 | STDMETHODIMP HostNetworkInterface::COMGETTER(Type) (HostNetworkInterfaceType_T *aType)
|
---|
279 | {
|
---|
280 | CheckComArgOutPointerValid(aType);
|
---|
281 |
|
---|
282 | AutoCaller autoCaller (this);
|
---|
283 | CheckComRCReturnRC (autoCaller.rc());
|
---|
284 |
|
---|
285 | *aType = m.type;
|
---|
286 |
|
---|
287 | return S_OK;
|
---|
288 | }
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Returns the current state of the host network interface.
|
---|
292 | *
|
---|
293 | * @returns COM status code
|
---|
294 | * @param aStatus address of result pointer
|
---|
295 | */
|
---|
296 | STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
|
---|
297 | {
|
---|
298 | CheckComArgOutPointerValid(aStatus);
|
---|
299 |
|
---|
300 | AutoCaller autoCaller (this);
|
---|
301 | CheckComRCReturnRC (autoCaller.rc());
|
---|
302 |
|
---|
303 | *aStatus = m.status;
|
---|
304 |
|
---|
305 | return S_OK;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|