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