1 | /* $Id: NetIf-win.cpp 22472 2009-08-26 14:19:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Main - NetIfList, Windows implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 | /*******************************************************************************
|
---|
25 | * Header Files *
|
---|
26 | *******************************************************************************/
|
---|
27 | #define LOG_GROUP LOG_GROUP_MAIN
|
---|
28 |
|
---|
29 | #include <iprt/asm.h>
|
---|
30 | #include <iprt/err.h>
|
---|
31 | #include <list>
|
---|
32 |
|
---|
33 | #define _WIN32_DCOM
|
---|
34 | #include <winsock2.h>
|
---|
35 | #include <ws2tcpip.h>
|
---|
36 | #include <windows.h>
|
---|
37 |
|
---|
38 | #ifdef VBOX_WITH_NETFLT
|
---|
39 | #include "VBox/WinNetConfig.h"
|
---|
40 | #include "devguid.h"
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iphlpapi.h>
|
---|
44 |
|
---|
45 | #include "Logging.h"
|
---|
46 | #include "HostNetworkInterfaceImpl.h"
|
---|
47 | #include "ProgressImpl.h"
|
---|
48 | #include "VirtualBoxImpl.h"
|
---|
49 | #include "netif.h"
|
---|
50 |
|
---|
51 | #ifdef VBOX_WITH_NETFLT
|
---|
52 | #include <Wbemidl.h>
|
---|
53 | #include <comdef.h>
|
---|
54 |
|
---|
55 | #include "svchlp.h"
|
---|
56 |
|
---|
57 | #include <shellapi.h>
|
---|
58 | #define INITGUID
|
---|
59 | #include <guiddef.h>
|
---|
60 | #include <devguid.h>
|
---|
61 | #include <objbase.h>
|
---|
62 | #include <setupapi.h>
|
---|
63 | #include <shlobj.h>
|
---|
64 | #include <cfgmgr32.h>
|
---|
65 |
|
---|
66 | #define VBOX_APP_NAME L"VirtualBox"
|
---|
67 |
|
---|
68 | static int collectNetIfInfo(Bstr &strName, Guid &guid, PNETIFINFO pInfo)
|
---|
69 | {
|
---|
70 | DWORD dwRc;
|
---|
71 | int rc = VINF_SUCCESS;
|
---|
72 | /*
|
---|
73 | * Most of the hosts probably have less than 10 adapters,
|
---|
74 | * so we'll mostly succeed from the first attempt.
|
---|
75 | */
|
---|
76 | ULONG uBufLen = sizeof(IP_ADAPTER_ADDRESSES) * 10;
|
---|
77 | PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)RTMemAlloc(uBufLen);
|
---|
78 | if (!pAddresses)
|
---|
79 | return VERR_NO_MEMORY;
|
---|
80 | dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
|
---|
81 | if (dwRc == ERROR_BUFFER_OVERFLOW)
|
---|
82 | {
|
---|
83 | /* Impressive! More than 10 adapters! Get more memory and try again. */
|
---|
84 | RTMemFree(pAddresses);
|
---|
85 | pAddresses = (PIP_ADAPTER_ADDRESSES)RTMemAlloc(uBufLen);
|
---|
86 | if (!pAddresses)
|
---|
87 | return VERR_NO_MEMORY;
|
---|
88 | dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
|
---|
89 | }
|
---|
90 | if (dwRc == NO_ERROR)
|
---|
91 | {
|
---|
92 | PIP_ADAPTER_ADDRESSES pAdapter;
|
---|
93 | for (pAdapter = pAddresses; pAdapter; pAdapter = pAdapter->Next)
|
---|
94 | {
|
---|
95 | char *pszUuid = RTStrDup(pAdapter->AdapterName);
|
---|
96 | size_t len = strlen(pszUuid) - 1;
|
---|
97 | if (pszUuid[0] == '{' && pszUuid[len] == '}')
|
---|
98 | {
|
---|
99 | pszUuid[len] = 0;
|
---|
100 | if (!RTUuidCompareStr(&pInfo->Uuid, pszUuid + 1))
|
---|
101 | {
|
---|
102 | bool fIPFound, fIPv6Found;
|
---|
103 | PIP_ADAPTER_UNICAST_ADDRESS pAddr;
|
---|
104 | fIPFound = fIPv6Found = false;
|
---|
105 | for (pAddr = pAdapter->FirstUnicastAddress; pAddr; pAddr = pAddr->Next)
|
---|
106 | {
|
---|
107 | switch (pAddr->Address.lpSockaddr->sa_family)
|
---|
108 | {
|
---|
109 | case AF_INET:
|
---|
110 | if (!fIPFound)
|
---|
111 | {
|
---|
112 | fIPFound = true;
|
---|
113 | memcpy(&pInfo->IPAddress,
|
---|
114 | &((struct sockaddr_in *)pAddr->Address.lpSockaddr)->sin_addr.s_addr,
|
---|
115 | sizeof(pInfo->IPAddress));
|
---|
116 | }
|
---|
117 | break;
|
---|
118 | case AF_INET6:
|
---|
119 | if (!fIPv6Found)
|
---|
120 | {
|
---|
121 | fIPv6Found = true;
|
---|
122 | memcpy(&pInfo->IPv6Address,
|
---|
123 | ((struct sockaddr_in6 *)pAddr->Address.lpSockaddr)->sin6_addr.s6_addr,
|
---|
124 | sizeof(pInfo->IPv6Address));
|
---|
125 | }
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | PIP_ADAPTER_PREFIX pPrefix;
|
---|
130 | fIPFound = fIPv6Found = false;
|
---|
131 | for (pPrefix = pAdapter->FirstPrefix; pPrefix; pPrefix = pPrefix->Next)
|
---|
132 | {
|
---|
133 | switch (pPrefix->Address.lpSockaddr->sa_family)
|
---|
134 | {
|
---|
135 | case AF_INET:
|
---|
136 | if (!fIPFound)
|
---|
137 | {
|
---|
138 | fIPFound = true;
|
---|
139 | ASMBitSetRange(&pInfo->IPNetMask, 0, pPrefix->PrefixLength);
|
---|
140 | }
|
---|
141 | break;
|
---|
142 | case AF_INET6:
|
---|
143 | if (!fIPv6Found)
|
---|
144 | {
|
---|
145 | fIPv6Found = true;
|
---|
146 | ASMBitSetRange(&pInfo->IPv6NetMask, 0, pPrefix->PrefixLength);
|
---|
147 | }
|
---|
148 | break;
|
---|
149 | }
|
---|
150 | }
|
---|
151 | if (sizeof(pInfo->MACAddress) != pAdapter->PhysicalAddressLength)
|
---|
152 | Log(("collectNetIfInfo: Unexpected physical address length: %u\n", pAdapter->PhysicalAddressLength));
|
---|
153 | else
|
---|
154 | memcpy(pInfo->MACAddress.au8, pAdapter->PhysicalAddress, sizeof(pInfo->MACAddress));
|
---|
155 | pInfo->enmMediumType = NETIF_T_ETHERNET;
|
---|
156 | pInfo->enmStatus = pAdapter->OperStatus == IfOperStatusUp ? NETIF_S_UP : NETIF_S_DOWN;
|
---|
157 | RTStrFree(pszUuid);
|
---|
158 | break;
|
---|
159 | }
|
---|
160 | }
|
---|
161 | RTStrFree(pszUuid);
|
---|
162 | }
|
---|
163 |
|
---|
164 | ADAPTER_SETTINGS Settings;
|
---|
165 | HRESULT hr = VBoxNetCfgWinGetAdapterSettings((const GUID *)guid.raw(), &Settings);
|
---|
166 | if(hr == S_OK)
|
---|
167 | {
|
---|
168 | if(Settings.ip)
|
---|
169 | {
|
---|
170 | pInfo->IPAddress.u = Settings.ip;
|
---|
171 | pInfo->IPNetMask.u = Settings.mask;
|
---|
172 | }
|
---|
173 | pInfo->bDhcpEnabled = Settings.bDhcp;
|
---|
174 | }
|
---|
175 | else
|
---|
176 | {
|
---|
177 | pInfo->bDhcpEnabled = false;
|
---|
178 | }
|
---|
179 | }
|
---|
180 | RTMemFree(pAddresses);
|
---|
181 |
|
---|
182 | return VINF_SUCCESS;
|
---|
183 | }
|
---|
184 |
|
---|
185 | /* svc helper func */
|
---|
186 |
|
---|
187 | struct StaticIpConfig
|
---|
188 | {
|
---|
189 | ULONG IPAddress;
|
---|
190 | ULONG IPNetMask;
|
---|
191 | };
|
---|
192 |
|
---|
193 | struct StaticIpV6Config
|
---|
194 | {
|
---|
195 | BSTR IPV6Address;
|
---|
196 | ULONG IPV6NetMaskLength;
|
---|
197 | };
|
---|
198 |
|
---|
199 | struct NetworkInterfaceHelperClientData
|
---|
200 | {
|
---|
201 | SVCHlpMsg::Code msgCode;
|
---|
202 | /* for SVCHlpMsg::CreateHostOnlyNetworkInterface */
|
---|
203 | Bstr name;
|
---|
204 | ComObjPtr<HostNetworkInterface> iface;
|
---|
205 | ComObjPtr<VirtualBox> vBox;
|
---|
206 | /* for SVCHlpMsg::RemoveHostOnlyNetworkInterface */
|
---|
207 | Guid guid;
|
---|
208 |
|
---|
209 | union
|
---|
210 | {
|
---|
211 | StaticIpConfig StaticIP;
|
---|
212 | StaticIpV6Config StaticIPV6;
|
---|
213 | } u;
|
---|
214 |
|
---|
215 |
|
---|
216 | };
|
---|
217 |
|
---|
218 | static HRESULT netIfNetworkInterfaceHelperClient (SVCHlpClient *aClient,
|
---|
219 | Progress *aProgress,
|
---|
220 | void *aUser, int *aVrc)
|
---|
221 | {
|
---|
222 | LogFlowFuncEnter();
|
---|
223 | LogFlowFunc (("aClient={%p}, aProgress={%p}, aUser={%p}\n",
|
---|
224 | aClient, aProgress, aUser));
|
---|
225 |
|
---|
226 | AssertReturn((aClient == NULL && aProgress == NULL && aVrc == NULL) ||
|
---|
227 | (aClient != NULL && aProgress != NULL && aVrc != NULL),
|
---|
228 | E_POINTER);
|
---|
229 | AssertReturn(aUser, E_POINTER);
|
---|
230 |
|
---|
231 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
232 | d (static_cast <NetworkInterfaceHelperClientData *> (aUser));
|
---|
233 |
|
---|
234 | if (aClient == NULL)
|
---|
235 | {
|
---|
236 | /* "cleanup only" mode, just return (it will free aUser) */
|
---|
237 | return S_OK;
|
---|
238 | }
|
---|
239 |
|
---|
240 | HRESULT rc = S_OK;
|
---|
241 | int vrc = VINF_SUCCESS;
|
---|
242 |
|
---|
243 | switch (d->msgCode)
|
---|
244 | {
|
---|
245 | case SVCHlpMsg::CreateHostOnlyNetworkInterface:
|
---|
246 | {
|
---|
247 | LogFlowFunc (("CreateHostOnlyNetworkInterface:\n"));
|
---|
248 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
249 |
|
---|
250 | /* write message and parameters */
|
---|
251 | vrc = aClient->write (d->msgCode);
|
---|
252 | if (RT_FAILURE(vrc)) break;
|
---|
253 | // vrc = aClient->write (Utf8Str (d->name));
|
---|
254 | // if (RT_FAILURE(vrc)) break;
|
---|
255 |
|
---|
256 | /* wait for a reply */
|
---|
257 | bool endLoop = false;
|
---|
258 | while (!endLoop)
|
---|
259 | {
|
---|
260 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
261 |
|
---|
262 | vrc = aClient->read (reply);
|
---|
263 | if (RT_FAILURE(vrc)) break;
|
---|
264 |
|
---|
265 | switch (reply)
|
---|
266 | {
|
---|
267 | case SVCHlpMsg::CreateHostOnlyNetworkInterface_OK:
|
---|
268 | {
|
---|
269 | /* read the GUID */
|
---|
270 | Guid guid;
|
---|
271 | Utf8Str name;
|
---|
272 | vrc = aClient->read (name);
|
---|
273 | if (RT_FAILURE(vrc)) break;
|
---|
274 | vrc = aClient->read (guid);
|
---|
275 | if (RT_FAILURE(vrc)) break;
|
---|
276 |
|
---|
277 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", guid.raw()));
|
---|
278 |
|
---|
279 | /* initialize the object returned to the caller by
|
---|
280 | * CreateHostOnlyNetworkInterface() */
|
---|
281 | rc = d->iface->init (Bstr(name), guid, HostNetworkInterfaceType_HostOnly);
|
---|
282 | if(SUCCEEDED(rc))
|
---|
283 | {
|
---|
284 | rc = d->iface->setVirtualBox(d->vBox);
|
---|
285 | if(SUCCEEDED(rc))
|
---|
286 | {
|
---|
287 | rc = d->iface->updateConfig();
|
---|
288 | }
|
---|
289 | }
|
---|
290 | endLoop = true;
|
---|
291 | break;
|
---|
292 | }
|
---|
293 | case SVCHlpMsg::Error:
|
---|
294 | {
|
---|
295 | /* read the error message */
|
---|
296 | Utf8Str errMsg;
|
---|
297 | vrc = aClient->read (errMsg);
|
---|
298 | if (RT_FAILURE(vrc)) break;
|
---|
299 |
|
---|
300 | rc = E_FAIL;//TODO: setError (E_FAIL, errMsg);
|
---|
301 | endLoop = true;
|
---|
302 | break;
|
---|
303 | }
|
---|
304 | default:
|
---|
305 | {
|
---|
306 | endLoop = true;
|
---|
307 | rc = E_FAIL;//TODO: ComAssertMsgFailedBreak ((
|
---|
308 | //"Invalid message code %d (%08lX)\n",
|
---|
309 | //reply, reply),
|
---|
310 | //rc = E_FAIL);
|
---|
311 | }
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | break;
|
---|
316 | }
|
---|
317 | case SVCHlpMsg::RemoveHostOnlyNetworkInterface:
|
---|
318 | {
|
---|
319 | LogFlowFunc (("RemoveHostOnlyNetworkInterface:\n"));
|
---|
320 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", d->guid.raw()));
|
---|
321 |
|
---|
322 | /* write message and parameters */
|
---|
323 | vrc = aClient->write (d->msgCode);
|
---|
324 | if (RT_FAILURE(vrc)) break;
|
---|
325 | vrc = aClient->write (d->guid);
|
---|
326 | if (RT_FAILURE(vrc)) break;
|
---|
327 |
|
---|
328 | /* wait for a reply */
|
---|
329 | bool endLoop = false;
|
---|
330 | while (!endLoop)
|
---|
331 | {
|
---|
332 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
333 |
|
---|
334 | vrc = aClient->read (reply);
|
---|
335 | if (RT_FAILURE(vrc)) break;
|
---|
336 |
|
---|
337 | switch (reply)
|
---|
338 | {
|
---|
339 | case SVCHlpMsg::OK:
|
---|
340 | {
|
---|
341 | /* no parameters */
|
---|
342 | rc = S_OK;
|
---|
343 | endLoop = true;
|
---|
344 | break;
|
---|
345 | }
|
---|
346 | case SVCHlpMsg::Error:
|
---|
347 | {
|
---|
348 | /* read the error message */
|
---|
349 | Utf8Str errMsg;
|
---|
350 | vrc = aClient->read (errMsg);
|
---|
351 | if (RT_FAILURE(vrc)) break;
|
---|
352 |
|
---|
353 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
354 | endLoop = true;
|
---|
355 | break;
|
---|
356 | }
|
---|
357 | default:
|
---|
358 | {
|
---|
359 | endLoop = true;
|
---|
360 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
361 | //"Invalid message code %d (%08lX)\n",
|
---|
362 | //reply, reply),
|
---|
363 | //rc = E_FAIL);
|
---|
364 | }
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 | break;
|
---|
369 | }
|
---|
370 | case SVCHlpMsg::EnableDynamicIpConfig: /* see usage in code */
|
---|
371 | {
|
---|
372 | LogFlowFunc (("EnableDynamicIpConfig:\n"));
|
---|
373 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
374 |
|
---|
375 | /* write message and parameters */
|
---|
376 | vrc = aClient->write (d->msgCode);
|
---|
377 | if (RT_FAILURE(vrc)) break;
|
---|
378 | vrc = aClient->write (d->guid);
|
---|
379 | if (RT_FAILURE(vrc)) break;
|
---|
380 |
|
---|
381 | /* wait for a reply */
|
---|
382 | bool endLoop = false;
|
---|
383 | while (!endLoop)
|
---|
384 | {
|
---|
385 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
386 |
|
---|
387 | vrc = aClient->read (reply);
|
---|
388 | if (RT_FAILURE(vrc)) break;
|
---|
389 |
|
---|
390 | switch (reply)
|
---|
391 | {
|
---|
392 | case SVCHlpMsg::OK:
|
---|
393 | {
|
---|
394 | /* no parameters */
|
---|
395 | rc = d->iface->updateConfig();
|
---|
396 | endLoop = true;
|
---|
397 | break;
|
---|
398 | }
|
---|
399 | case SVCHlpMsg::Error:
|
---|
400 | {
|
---|
401 | /* read the error message */
|
---|
402 | Utf8Str errMsg;
|
---|
403 | vrc = aClient->read (errMsg);
|
---|
404 | if (RT_FAILURE(vrc)) break;
|
---|
405 |
|
---|
406 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
407 | endLoop = true;
|
---|
408 | break;
|
---|
409 | }
|
---|
410 | default:
|
---|
411 | {
|
---|
412 | endLoop = true;
|
---|
413 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
414 | //"Invalid message code %d (%08lX)\n",
|
---|
415 | //reply, reply),
|
---|
416 | //rc = E_FAIL);
|
---|
417 | }
|
---|
418 | }
|
---|
419 | }
|
---|
420 |
|
---|
421 | break;
|
---|
422 | }
|
---|
423 | case SVCHlpMsg::EnableStaticIpConfig: /* see usage in code */
|
---|
424 | {
|
---|
425 | LogFlowFunc (("EnableStaticIpConfig:\n"));
|
---|
426 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
427 |
|
---|
428 | /* write message and parameters */
|
---|
429 | vrc = aClient->write (d->msgCode);
|
---|
430 | if (RT_FAILURE(vrc)) break;
|
---|
431 | vrc = aClient->write (d->guid);
|
---|
432 | if (RT_FAILURE(vrc)) break;
|
---|
433 | vrc = aClient->write (d->u.StaticIP.IPAddress);
|
---|
434 | if (RT_FAILURE(vrc)) break;
|
---|
435 | vrc = aClient->write (d->u.StaticIP.IPNetMask);
|
---|
436 | if (RT_FAILURE(vrc)) break;
|
---|
437 |
|
---|
438 | /* wait for a reply */
|
---|
439 | bool endLoop = false;
|
---|
440 | while (!endLoop)
|
---|
441 | {
|
---|
442 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
443 |
|
---|
444 | vrc = aClient->read (reply);
|
---|
445 | if (RT_FAILURE(vrc)) break;
|
---|
446 |
|
---|
447 | switch (reply)
|
---|
448 | {
|
---|
449 | case SVCHlpMsg::OK:
|
---|
450 | {
|
---|
451 | /* no parameters */
|
---|
452 | rc = d->iface->updateConfig();
|
---|
453 | endLoop = true;
|
---|
454 | break;
|
---|
455 | }
|
---|
456 | case SVCHlpMsg::Error:
|
---|
457 | {
|
---|
458 | /* read the error message */
|
---|
459 | Utf8Str errMsg;
|
---|
460 | vrc = aClient->read (errMsg);
|
---|
461 | if (RT_FAILURE(vrc)) break;
|
---|
462 |
|
---|
463 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
464 | endLoop = true;
|
---|
465 | break;
|
---|
466 | }
|
---|
467 | default:
|
---|
468 | {
|
---|
469 | endLoop = true;
|
---|
470 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
471 | //"Invalid message code %d (%08lX)\n",
|
---|
472 | //reply, reply),
|
---|
473 | //rc = E_FAIL);
|
---|
474 | }
|
---|
475 | }
|
---|
476 | }
|
---|
477 |
|
---|
478 | break;
|
---|
479 | }
|
---|
480 | case SVCHlpMsg::EnableStaticIpConfigV6: /* see usage in code */
|
---|
481 | {
|
---|
482 | LogFlowFunc (("EnableStaticIpConfigV6:\n"));
|
---|
483 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
484 |
|
---|
485 | /* write message and parameters */
|
---|
486 | vrc = aClient->write (d->msgCode);
|
---|
487 | if (RT_FAILURE(vrc)) break;
|
---|
488 | vrc = aClient->write (d->guid);
|
---|
489 | if (RT_FAILURE(vrc)) break;
|
---|
490 | vrc = aClient->write (Utf8Str(d->u.StaticIPV6.IPV6Address));
|
---|
491 | if (RT_FAILURE(vrc)) break;
|
---|
492 | vrc = aClient->write (d->u.StaticIPV6.IPV6NetMaskLength);
|
---|
493 | if (RT_FAILURE(vrc)) break;
|
---|
494 |
|
---|
495 | /* wait for a reply */
|
---|
496 | bool endLoop = false;
|
---|
497 | while (!endLoop)
|
---|
498 | {
|
---|
499 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
500 |
|
---|
501 | vrc = aClient->read (reply);
|
---|
502 | if (RT_FAILURE(vrc)) break;
|
---|
503 |
|
---|
504 | switch (reply)
|
---|
505 | {
|
---|
506 | case SVCHlpMsg::OK:
|
---|
507 | {
|
---|
508 | /* no parameters */
|
---|
509 | rc = d->iface->updateConfig();
|
---|
510 | endLoop = true;
|
---|
511 | break;
|
---|
512 | }
|
---|
513 | case SVCHlpMsg::Error:
|
---|
514 | {
|
---|
515 | /* read the error message */
|
---|
516 | Utf8Str errMsg;
|
---|
517 | vrc = aClient->read (errMsg);
|
---|
518 | if (RT_FAILURE(vrc)) break;
|
---|
519 |
|
---|
520 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
521 | endLoop = true;
|
---|
522 | break;
|
---|
523 | }
|
---|
524 | default:
|
---|
525 | {
|
---|
526 | endLoop = true;
|
---|
527 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
528 | //"Invalid message code %d (%08lX)\n",
|
---|
529 | //reply, reply),
|
---|
530 | //rc = E_FAIL);
|
---|
531 | }
|
---|
532 | }
|
---|
533 | }
|
---|
534 |
|
---|
535 | break;
|
---|
536 | }
|
---|
537 | case SVCHlpMsg::DhcpRediscover: /* see usage in code */
|
---|
538 | {
|
---|
539 | LogFlowFunc (("DhcpRediscover:\n"));
|
---|
540 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
541 |
|
---|
542 | /* write message and parameters */
|
---|
543 | vrc = aClient->write (d->msgCode);
|
---|
544 | if (RT_FAILURE(vrc)) break;
|
---|
545 | vrc = aClient->write (d->guid);
|
---|
546 | if (RT_FAILURE(vrc)) break;
|
---|
547 |
|
---|
548 | /* wait for a reply */
|
---|
549 | bool endLoop = false;
|
---|
550 | while (!endLoop)
|
---|
551 | {
|
---|
552 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
553 |
|
---|
554 | vrc = aClient->read (reply);
|
---|
555 | if (RT_FAILURE(vrc)) break;
|
---|
556 |
|
---|
557 | switch (reply)
|
---|
558 | {
|
---|
559 | case SVCHlpMsg::OK:
|
---|
560 | {
|
---|
561 | /* no parameters */
|
---|
562 | rc = d->iface->updateConfig();
|
---|
563 | endLoop = true;
|
---|
564 | break;
|
---|
565 | }
|
---|
566 | case SVCHlpMsg::Error:
|
---|
567 | {
|
---|
568 | /* read the error message */
|
---|
569 | Utf8Str errMsg;
|
---|
570 | vrc = aClient->read (errMsg);
|
---|
571 | if (RT_FAILURE(vrc)) break;
|
---|
572 |
|
---|
573 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
574 | endLoop = true;
|
---|
575 | break;
|
---|
576 | }
|
---|
577 | default:
|
---|
578 | {
|
---|
579 | endLoop = true;
|
---|
580 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
581 | //"Invalid message code %d (%08lX)\n",
|
---|
582 | //reply, reply),
|
---|
583 | //rc = E_FAIL);
|
---|
584 | }
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 | break;
|
---|
589 | }
|
---|
590 | default:
|
---|
591 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
592 | // "Invalid message code %d (%08lX)\n",
|
---|
593 | // d->msgCode, d->msgCode),
|
---|
594 | // rc = E_FAIL);
|
---|
595 | }
|
---|
596 |
|
---|
597 | if (aVrc)
|
---|
598 | *aVrc = vrc;
|
---|
599 |
|
---|
600 | LogFlowFunc (("rc=0x%08X, vrc=%Rrc\n", rc, vrc));
|
---|
601 | LogFlowFuncLeave();
|
---|
602 | return rc;
|
---|
603 | }
|
---|
604 |
|
---|
605 |
|
---|
606 | int netIfNetworkInterfaceHelperServer (SVCHlpClient *aClient,
|
---|
607 | SVCHlpMsg::Code aMsgCode)
|
---|
608 | {
|
---|
609 | LogFlowFuncEnter();
|
---|
610 | LogFlowFunc (("aClient={%p}, aMsgCode=%d\n", aClient, aMsgCode));
|
---|
611 |
|
---|
612 | AssertReturn(aClient, VERR_INVALID_POINTER);
|
---|
613 |
|
---|
614 | int vrc = VINF_SUCCESS;
|
---|
615 | HRESULT hrc;
|
---|
616 |
|
---|
617 | switch (aMsgCode)
|
---|
618 | {
|
---|
619 | case SVCHlpMsg::CreateHostOnlyNetworkInterface:
|
---|
620 | {
|
---|
621 | LogFlowFunc (("CreateHostOnlyNetworkInterface:\n"));
|
---|
622 |
|
---|
623 | // Utf8Str name;
|
---|
624 | // vrc = aClient->read (name);
|
---|
625 | // if (RT_FAILURE(vrc)) break;
|
---|
626 |
|
---|
627 | Guid guid;
|
---|
628 | Utf8Str errMsg;
|
---|
629 | Bstr name;
|
---|
630 | Bstr bstrErr;
|
---|
631 |
|
---|
632 | hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface (NULL, false, guid.asOutParam(), name.asOutParam(), bstrErr.asOutParam());
|
---|
633 |
|
---|
634 | if (hrc == S_OK)
|
---|
635 | {
|
---|
636 | ULONG ip, mask;
|
---|
637 | hrc = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask);
|
---|
638 | if(hrc == S_OK)
|
---|
639 | {
|
---|
640 | /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip,
|
---|
641 | * i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter */
|
---|
642 | ip = ip | (1 << 24);
|
---|
643 | hrc = VBoxNetCfgWinEnableStaticIpConfig((const GUID*)guid.raw(), ip, mask);
|
---|
644 | }
|
---|
645 |
|
---|
646 | /* write success followed by GUID */
|
---|
647 | vrc = aClient->write (SVCHlpMsg::CreateHostOnlyNetworkInterface_OK);
|
---|
648 | if (RT_FAILURE(vrc)) break;
|
---|
649 | vrc = aClient->write (Utf8Str (name));
|
---|
650 | if (RT_FAILURE(vrc)) break;
|
---|
651 | vrc = aClient->write (guid);
|
---|
652 | if (RT_FAILURE(vrc)) break;
|
---|
653 | }
|
---|
654 | else
|
---|
655 | {
|
---|
656 | vrc = VERR_GENERAL_FAILURE;
|
---|
657 | errMsg = Utf8Str(bstrErr);
|
---|
658 | /* write failure followed by error message */
|
---|
659 | if (errMsg.isEmpty())
|
---|
660 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
661 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
662 | if (RT_FAILURE(vrc)) break;
|
---|
663 | vrc = aClient->write (errMsg);
|
---|
664 | if (RT_FAILURE(vrc)) break;
|
---|
665 | }
|
---|
666 |
|
---|
667 | break;
|
---|
668 | }
|
---|
669 | case SVCHlpMsg::RemoveHostOnlyNetworkInterface:
|
---|
670 | {
|
---|
671 | LogFlowFunc (("RemoveHostOnlyNetworkInterface:\n"));
|
---|
672 |
|
---|
673 | Guid guid;
|
---|
674 | Bstr bstrErr;
|
---|
675 |
|
---|
676 | vrc = aClient->read (guid);
|
---|
677 | if (RT_FAILURE(vrc)) break;
|
---|
678 |
|
---|
679 | Utf8Str errMsg;
|
---|
680 | hrc = VBoxNetCfgWinRemoveHostOnlyNetworkInterface ((const GUID*)guid.raw(), bstrErr.asOutParam());
|
---|
681 |
|
---|
682 | if (hrc == S_OK)
|
---|
683 | {
|
---|
684 | /* write parameter-less success */
|
---|
685 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
686 | if (RT_FAILURE(vrc)) break;
|
---|
687 | }
|
---|
688 | else
|
---|
689 | {
|
---|
690 | vrc = VERR_GENERAL_FAILURE;
|
---|
691 | errMsg = Utf8Str(bstrErr);
|
---|
692 | /* write failure followed by error message */
|
---|
693 | if (errMsg.isEmpty())
|
---|
694 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
695 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
696 | if (RT_FAILURE(vrc)) break;
|
---|
697 | vrc = aClient->write (errMsg);
|
---|
698 | if (RT_FAILURE(vrc)) break;
|
---|
699 | }
|
---|
700 |
|
---|
701 | break;
|
---|
702 | }
|
---|
703 | case SVCHlpMsg::EnableStaticIpConfigV6:
|
---|
704 | {
|
---|
705 | LogFlowFunc (("EnableStaticIpConfigV6:\n"));
|
---|
706 |
|
---|
707 | Guid guid;
|
---|
708 | Utf8Str ipV6;
|
---|
709 | ULONG maskLengthV6;
|
---|
710 | vrc = aClient->read (guid);
|
---|
711 | if (RT_FAILURE(vrc)) break;
|
---|
712 | vrc = aClient->read (ipV6);
|
---|
713 | if (RT_FAILURE(vrc)) break;
|
---|
714 | vrc = aClient->read (maskLengthV6);
|
---|
715 | if (RT_FAILURE(vrc)) break;
|
---|
716 |
|
---|
717 | Utf8Str errMsg;
|
---|
718 | vrc = VERR_NOT_IMPLEMENTED;
|
---|
719 |
|
---|
720 | if (RT_SUCCESS(vrc))
|
---|
721 | {
|
---|
722 | /* write success followed by GUID */
|
---|
723 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
724 | if (RT_FAILURE(vrc)) break;
|
---|
725 | }
|
---|
726 | else
|
---|
727 | {
|
---|
728 | /* write failure followed by error message */
|
---|
729 | if (errMsg.isEmpty())
|
---|
730 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
731 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
732 | if (RT_FAILURE(vrc)) break;
|
---|
733 | vrc = aClient->write (errMsg);
|
---|
734 | if (RT_FAILURE(vrc)) break;
|
---|
735 | }
|
---|
736 |
|
---|
737 | break;
|
---|
738 | }
|
---|
739 | case SVCHlpMsg::EnableStaticIpConfig:
|
---|
740 | {
|
---|
741 | LogFlowFunc (("EnableStaticIpConfig:\n"));
|
---|
742 |
|
---|
743 | Guid guid;
|
---|
744 | ULONG ip, mask;
|
---|
745 | vrc = aClient->read (guid);
|
---|
746 | if (RT_FAILURE(vrc)) break;
|
---|
747 | vrc = aClient->read (ip);
|
---|
748 | if (RT_FAILURE(vrc)) break;
|
---|
749 | vrc = aClient->read (mask);
|
---|
750 | if (RT_FAILURE(vrc)) break;
|
---|
751 |
|
---|
752 | Utf8Str errMsg;
|
---|
753 | hrc = VBoxNetCfgWinEnableStaticIpConfig ((const GUID *)guid.raw(), ip, mask);
|
---|
754 |
|
---|
755 | if (hrc == S_OK)
|
---|
756 | {
|
---|
757 | /* write success followed by GUID */
|
---|
758 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
759 | if (RT_FAILURE(vrc)) break;
|
---|
760 | }
|
---|
761 | else
|
---|
762 | {
|
---|
763 | vrc = VERR_GENERAL_FAILURE;
|
---|
764 | /* write failure followed by error message */
|
---|
765 | if (errMsg.isEmpty())
|
---|
766 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
767 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
768 | if (RT_FAILURE(vrc)) break;
|
---|
769 | vrc = aClient->write (errMsg);
|
---|
770 | if (RT_FAILURE(vrc)) break;
|
---|
771 | }
|
---|
772 |
|
---|
773 | break;
|
---|
774 | }
|
---|
775 | case SVCHlpMsg::EnableDynamicIpConfig:
|
---|
776 | {
|
---|
777 | LogFlowFunc (("EnableDynamicIpConfig:\n"));
|
---|
778 |
|
---|
779 | Guid guid;
|
---|
780 | vrc = aClient->read (guid);
|
---|
781 | if (RT_FAILURE(vrc)) break;
|
---|
782 |
|
---|
783 | Utf8Str errMsg;
|
---|
784 | hrc = VBoxNetCfgWinEnableDynamicIpConfig ((const GUID *)guid.raw());
|
---|
785 |
|
---|
786 | if (hrc == S_OK)
|
---|
787 | {
|
---|
788 | /* write success followed by GUID */
|
---|
789 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
790 | if (RT_FAILURE(vrc)) break;
|
---|
791 | }
|
---|
792 | else
|
---|
793 | {
|
---|
794 | vrc = VERR_GENERAL_FAILURE;
|
---|
795 | /* write failure followed by error message */
|
---|
796 | if (errMsg.isEmpty())
|
---|
797 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
798 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
799 | if (RT_FAILURE(vrc)) break;
|
---|
800 | vrc = aClient->write (errMsg);
|
---|
801 | if (RT_FAILURE(vrc)) break;
|
---|
802 | }
|
---|
803 |
|
---|
804 | break;
|
---|
805 | }
|
---|
806 | case SVCHlpMsg::DhcpRediscover:
|
---|
807 | {
|
---|
808 | LogFlowFunc (("DhcpRediscover:\n"));
|
---|
809 |
|
---|
810 | Guid guid;
|
---|
811 | vrc = aClient->read (guid);
|
---|
812 | if (RT_FAILURE(vrc)) break;
|
---|
813 |
|
---|
814 | Utf8Str errMsg;
|
---|
815 | hrc = VBoxNetCfgWinDhcpRediscover ((const GUID *)guid.raw());
|
---|
816 |
|
---|
817 | if (hrc == S_OK)
|
---|
818 | {
|
---|
819 | /* write success followed by GUID */
|
---|
820 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
821 | if (RT_FAILURE(vrc)) break;
|
---|
822 | }
|
---|
823 | else
|
---|
824 | {
|
---|
825 | vrc = VERR_GENERAL_FAILURE;
|
---|
826 | /* write failure followed by error message */
|
---|
827 | if (errMsg.isEmpty())
|
---|
828 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
829 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
830 | if (RT_FAILURE(vrc)) break;
|
---|
831 | vrc = aClient->write (errMsg);
|
---|
832 | if (RT_FAILURE(vrc)) break;
|
---|
833 | }
|
---|
834 |
|
---|
835 | break;
|
---|
836 | }
|
---|
837 | default:
|
---|
838 | AssertMsgFailedBreakStmt (
|
---|
839 | ("Invalid message code %d (%08lX)\n", aMsgCode, aMsgCode),
|
---|
840 | VERR_GENERAL_FAILURE);
|
---|
841 | }
|
---|
842 |
|
---|
843 | LogFlowFunc (("vrc=%Rrc\n", vrc));
|
---|
844 | LogFlowFuncLeave();
|
---|
845 | return vrc;
|
---|
846 | }
|
---|
847 |
|
---|
848 | /** @todo REMOVE. OBSOLETE NOW. */
|
---|
849 | /**
|
---|
850 | * Returns TRUE if the Windows version is 6.0 or greater (i.e. it's Vista and
|
---|
851 | * later OSes) and it has the UAC (User Account Control) feature enabled.
|
---|
852 | */
|
---|
853 | static BOOL IsUACEnabled()
|
---|
854 | {
|
---|
855 | LONG rc = 0;
|
---|
856 |
|
---|
857 | OSVERSIONINFOEX info;
|
---|
858 | ZeroMemory (&info, sizeof (OSVERSIONINFOEX));
|
---|
859 | info.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
|
---|
860 | rc = GetVersionEx ((OSVERSIONINFO *) &info);
|
---|
861 | AssertReturn(rc != 0, FALSE);
|
---|
862 |
|
---|
863 | LogFlowFunc (("dwMajorVersion=%d, dwMinorVersion=%d\n",
|
---|
864 | info.dwMajorVersion, info.dwMinorVersion));
|
---|
865 |
|
---|
866 | /* we are interested only in Vista (and newer versions...). In all
|
---|
867 | * earlier versions UAC is not present. */
|
---|
868 | if (info.dwMajorVersion < 6)
|
---|
869 | return FALSE;
|
---|
870 |
|
---|
871 | /* the default EnableLUA value is 1 (Enabled) */
|
---|
872 | DWORD dwEnableLUA = 1;
|
---|
873 |
|
---|
874 | HKEY hKey;
|
---|
875 | rc = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
|
---|
876 | "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
|
---|
877 | 0, KEY_QUERY_VALUE, &hKey);
|
---|
878 |
|
---|
879 | Assert (rc == ERROR_SUCCESS || rc == ERROR_PATH_NOT_FOUND);
|
---|
880 | if (rc == ERROR_SUCCESS)
|
---|
881 | {
|
---|
882 |
|
---|
883 | DWORD cbEnableLUA = sizeof (dwEnableLUA);
|
---|
884 | rc = RegQueryValueExA (hKey, "EnableLUA", NULL, NULL,
|
---|
885 | (LPBYTE) &dwEnableLUA, &cbEnableLUA);
|
---|
886 |
|
---|
887 | RegCloseKey (hKey);
|
---|
888 |
|
---|
889 | Assert (rc == ERROR_SUCCESS || rc == ERROR_FILE_NOT_FOUND);
|
---|
890 | }
|
---|
891 |
|
---|
892 | LogFlowFunc (("rc=%d, dwEnableLUA=%d\n", rc, dwEnableLUA));
|
---|
893 |
|
---|
894 | return dwEnableLUA == 1;
|
---|
895 | }
|
---|
896 |
|
---|
897 | /* end */
|
---|
898 |
|
---|
899 | static int vboxNetWinAddComponent(std::list <ComObjPtr<HostNetworkInterface> > * pPist, INetCfgComponent * pncc, HostNetworkInterfaceType enmType)
|
---|
900 | {
|
---|
901 | LPWSTR lpszName;
|
---|
902 | GUID IfGuid;
|
---|
903 | HRESULT hr;
|
---|
904 | int rc = VERR_GENERAL_FAILURE;
|
---|
905 |
|
---|
906 | hr = pncc->GetDisplayName( &lpszName );
|
---|
907 | Assert(hr == S_OK);
|
---|
908 | if(hr == S_OK)
|
---|
909 | {
|
---|
910 | size_t cUnicodeName = wcslen(lpszName) + 1;
|
---|
911 | size_t uniLen = (cUnicodeName * 2 + sizeof (OLECHAR) - 1) / sizeof (OLECHAR);
|
---|
912 | Bstr name (uniLen + 1 /* extra zero */);
|
---|
913 | wcscpy((wchar_t *) name.mutableRaw(), lpszName);
|
---|
914 |
|
---|
915 | hr = pncc->GetInstanceGuid(&IfGuid);
|
---|
916 | Assert(hr == S_OK);
|
---|
917 | if (hr == S_OK)
|
---|
918 | {
|
---|
919 | NETIFINFO Info;
|
---|
920 | memset(&Info, 0, sizeof(Info));
|
---|
921 | Info.Uuid = *(Guid(IfGuid).raw());
|
---|
922 | rc = collectNetIfInfo(name, Guid(IfGuid), &Info);
|
---|
923 | if (RT_FAILURE(rc))
|
---|
924 | {
|
---|
925 | Log(("vboxNetWinAddComponent: collectNetIfInfo() -> %Vrc\n", rc));
|
---|
926 | }
|
---|
927 | /* create a new object and add it to the list */
|
---|
928 | ComObjPtr<HostNetworkInterface> iface;
|
---|
929 | iface.createObject();
|
---|
930 | /* remove the curly bracket at the end */
|
---|
931 | if (SUCCEEDED(iface->init (name, enmType, &Info)))
|
---|
932 | {
|
---|
933 | pPist->push_back (iface);
|
---|
934 | rc = VINF_SUCCESS;
|
---|
935 | }
|
---|
936 | else
|
---|
937 | {
|
---|
938 | Assert(0);
|
---|
939 | }
|
---|
940 | }
|
---|
941 | CoTaskMemFree(lpszName);
|
---|
942 | }
|
---|
943 |
|
---|
944 | return rc;
|
---|
945 | }
|
---|
946 |
|
---|
947 | #endif /* VBOX_WITH_NETFLT */
|
---|
948 |
|
---|
949 |
|
---|
950 | static int netIfListHostAdapters(std::list <ComObjPtr<HostNetworkInterface> > &list)
|
---|
951 | {
|
---|
952 | #ifndef VBOX_WITH_NETFLT
|
---|
953 | /* VBoxNetAdp is available only when VBOX_WITH_NETFLT is enabled */
|
---|
954 | return VERR_NOT_IMPLEMENTED;
|
---|
955 | #else /* # if defined VBOX_WITH_NETFLT */
|
---|
956 | INetCfg *pNc;
|
---|
957 | INetCfgComponent *pMpNcc;
|
---|
958 | LPWSTR lpszApp = NULL;
|
---|
959 | HRESULT hr;
|
---|
960 | IEnumNetCfgComponent *pEnumComponent;
|
---|
961 |
|
---|
962 | /* we are using the INetCfg API for getting the list of miniports */
|
---|
963 | hr = VBoxNetCfgWinQueryINetCfg( FALSE,
|
---|
964 | VBOX_APP_NAME,
|
---|
965 | &pNc,
|
---|
966 | &lpszApp );
|
---|
967 | Assert(hr == S_OK);
|
---|
968 | if(hr == S_OK)
|
---|
969 | {
|
---|
970 | hr = VBoxNetCfgWinGetComponentEnum(pNc, &GUID_DEVCLASS_NET, &pEnumComponent);
|
---|
971 | if(hr == S_OK)
|
---|
972 | {
|
---|
973 | while((hr = VBoxNetCfgWinGetNextComponent(pEnumComponent, &pMpNcc)) == S_OK)
|
---|
974 | {
|
---|
975 | ULONG uComponentStatus;
|
---|
976 | hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
|
---|
977 | //#ifndef DEBUG_bird
|
---|
978 | // Assert(hr == S_OK);
|
---|
979 | //#endif
|
---|
980 | if(hr == S_OK)
|
---|
981 | {
|
---|
982 | if(uComponentStatus == 0)
|
---|
983 | {
|
---|
984 | LPWSTR pId;
|
---|
985 | hr = pMpNcc->GetId(&pId);
|
---|
986 | Assert(hr == S_OK);
|
---|
987 | if(hr == S_OK)
|
---|
988 | {
|
---|
989 | if(!_wcsnicmp(pId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2))
|
---|
990 | {
|
---|
991 | vboxNetWinAddComponent(&list, pMpNcc, HostNetworkInterfaceType_HostOnly);
|
---|
992 | }
|
---|
993 | CoTaskMemFree(pId);
|
---|
994 | }
|
---|
995 | }
|
---|
996 | }
|
---|
997 | VBoxNetCfgWinReleaseRef(pMpNcc);
|
---|
998 | }
|
---|
999 | Assert(hr == S_OK || hr == S_FALSE);
|
---|
1000 |
|
---|
1001 | VBoxNetCfgWinReleaseRef(pEnumComponent);
|
---|
1002 | }
|
---|
1003 | else
|
---|
1004 | {
|
---|
1005 | LogRel(("failed to get the sun_VBoxNetFlt component, error (0x%x)", hr));
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
|
---|
1009 | }
|
---|
1010 | else if(lpszApp)
|
---|
1011 | {
|
---|
1012 | CoTaskMemFree(lpszApp);
|
---|
1013 | }
|
---|
1014 | #endif /* # if defined VBOX_WITH_NETFLT */
|
---|
1015 | return VINF_SUCCESS;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *pInfo)
|
---|
1019 | {
|
---|
1020 | #ifndef VBOX_WITH_NETFLT
|
---|
1021 | return VERR_NOT_IMPLEMENTED;
|
---|
1022 | #else
|
---|
1023 | Bstr name;
|
---|
1024 | HRESULT hr = pIf->COMGETTER(Name)(name.asOutParam());
|
---|
1025 | if(hr == S_OK)
|
---|
1026 | {
|
---|
1027 | Bstr IfGuid;
|
---|
1028 | hr = pIf->COMGETTER(Id)(IfGuid.asOutParam());
|
---|
1029 | Assert(hr == S_OK);
|
---|
1030 | if (hr == S_OK)
|
---|
1031 | {
|
---|
1032 | memset(pInfo, 0, sizeof(NETIFINFO));
|
---|
1033 | Guid guid(IfGuid);
|
---|
1034 | pInfo->Uuid = *(guid.raw());
|
---|
1035 |
|
---|
1036 | return collectNetIfInfo(name, guid, pInfo);
|
---|
1037 | }
|
---|
1038 | }
|
---|
1039 | return VERR_GENERAL_FAILURE;
|
---|
1040 | #endif
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | int NetIfGetConfigByName(PNETIFINFO)
|
---|
1044 | {
|
---|
1045 | return VERR_NOT_IMPLEMENTED;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox,
|
---|
1049 | IHostNetworkInterface **aHostNetworkInterface,
|
---|
1050 | IProgress **aProgress)
|
---|
1051 | {
|
---|
1052 | #ifndef VBOX_WITH_NETFLT
|
---|
1053 | return VERR_NOT_IMPLEMENTED;
|
---|
1054 | #else
|
---|
1055 | /* create a progress object */
|
---|
1056 | ComObjPtr<Progress> progress;
|
---|
1057 | progress.createObject();
|
---|
1058 |
|
---|
1059 | ComPtr<IHost> host;
|
---|
1060 | HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());
|
---|
1061 | if(SUCCEEDED(rc))
|
---|
1062 | {
|
---|
1063 | rc = progress->init (pVBox, host,
|
---|
1064 | Bstr (_T ("Creating host only network interface")),
|
---|
1065 | FALSE /* aCancelable */);
|
---|
1066 | if(SUCCEEDED(rc))
|
---|
1067 | {
|
---|
1068 | CheckComRCReturnRC(rc);
|
---|
1069 | progress.queryInterfaceTo(aProgress);
|
---|
1070 |
|
---|
1071 | /* create a new uninitialized host interface object */
|
---|
1072 | ComObjPtr<HostNetworkInterface> iface;
|
---|
1073 | iface.createObject();
|
---|
1074 | iface.queryInterfaceTo(aHostNetworkInterface);
|
---|
1075 |
|
---|
1076 | /* create the networkInterfaceHelperClient() argument */
|
---|
1077 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1078 | d (new NetworkInterfaceHelperClientData());
|
---|
1079 | AssertReturn(d.get(), E_OUTOFMEMORY);
|
---|
1080 |
|
---|
1081 | d->msgCode = SVCHlpMsg::CreateHostOnlyNetworkInterface;
|
---|
1082 | // d->name = aName;
|
---|
1083 | d->iface = iface;
|
---|
1084 | d->vBox = pVBox;
|
---|
1085 |
|
---|
1086 | rc = pVBox->startSVCHelperClient (
|
---|
1087 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1088 | netIfNetworkInterfaceHelperClient,
|
---|
1089 | static_cast <void *> (d.get()),
|
---|
1090 | progress);
|
---|
1091 |
|
---|
1092 | if (SUCCEEDED(rc))
|
---|
1093 | {
|
---|
1094 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1095 | d.release();
|
---|
1096 | }
|
---|
1097 | }
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1101 | #endif
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId,
|
---|
1105 | IProgress **aProgress)
|
---|
1106 | {
|
---|
1107 | #ifndef VBOX_WITH_NETFLT
|
---|
1108 | return VERR_NOT_IMPLEMENTED;
|
---|
1109 | #else
|
---|
1110 | /* create a progress object */
|
---|
1111 | ComObjPtr<Progress> progress;
|
---|
1112 | progress.createObject();
|
---|
1113 | ComPtr<IHost> host;
|
---|
1114 | HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());
|
---|
1115 | if(SUCCEEDED(rc))
|
---|
1116 | {
|
---|
1117 | rc = progress->init (pVBox, host,
|
---|
1118 | Bstr (_T ("Removing host network interface")),
|
---|
1119 | FALSE /* aCancelable */);
|
---|
1120 | if(SUCCEEDED(rc))
|
---|
1121 | {
|
---|
1122 | CheckComRCReturnRC(rc);
|
---|
1123 | progress.queryInterfaceTo(aProgress);
|
---|
1124 |
|
---|
1125 | /* create the networkInterfaceHelperClient() argument */
|
---|
1126 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1127 | d (new NetworkInterfaceHelperClientData());
|
---|
1128 | AssertReturn(d.get(), E_OUTOFMEMORY);
|
---|
1129 |
|
---|
1130 | d->msgCode = SVCHlpMsg::RemoveHostOnlyNetworkInterface;
|
---|
1131 | d->guid = aId;
|
---|
1132 |
|
---|
1133 | rc = pVBox->startSVCHelperClient (
|
---|
1134 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1135 | netIfNetworkInterfaceHelperClient,
|
---|
1136 | static_cast <void *> (d.get()),
|
---|
1137 | progress);
|
---|
1138 |
|
---|
1139 | if (SUCCEEDED(rc))
|
---|
1140 | {
|
---|
1141 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1142 | d.release();
|
---|
1143 | }
|
---|
1144 | }
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1148 | #endif
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | int NetIfEnableStaticIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG ip, ULONG mask)
|
---|
1152 | {
|
---|
1153 | #ifndef VBOX_WITH_NETFLT
|
---|
1154 | return VERR_NOT_IMPLEMENTED;
|
---|
1155 | #else
|
---|
1156 | HRESULT rc;
|
---|
1157 | Bstr guid;
|
---|
1158 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1159 | if(SUCCEEDED(rc))
|
---|
1160 | {
|
---|
1161 | // ComPtr<VirtualBox> vBox;
|
---|
1162 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1163 | // if(SUCCEEDED(rc))
|
---|
1164 | {
|
---|
1165 | /* create a progress object */
|
---|
1166 | ComObjPtr<Progress> progress;
|
---|
1167 | progress.createObject();
|
---|
1168 | // ComPtr<IHost> host;
|
---|
1169 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1170 | // if(SUCCEEDED(rc))
|
---|
1171 | {
|
---|
1172 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1173 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1174 | FALSE /* aCancelable */);
|
---|
1175 | if(SUCCEEDED(rc))
|
---|
1176 | {
|
---|
1177 | CheckComRCReturnRC(rc);
|
---|
1178 | // progress.queryInterfaceTo(aProgress);
|
---|
1179 |
|
---|
1180 | /* create the networkInterfaceHelperClient() argument */
|
---|
1181 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1182 | d (new NetworkInterfaceHelperClientData());
|
---|
1183 | AssertReturn(d.get(), E_OUTOFMEMORY);
|
---|
1184 |
|
---|
1185 | d->msgCode = SVCHlpMsg::EnableStaticIpConfig;
|
---|
1186 | d->guid = Guid(guid);
|
---|
1187 | d->iface = pIf;
|
---|
1188 | d->u.StaticIP.IPAddress = ip;
|
---|
1189 | d->u.StaticIP.IPNetMask = mask;
|
---|
1190 |
|
---|
1191 | rc = vBox->startSVCHelperClient (
|
---|
1192 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1193 | netIfNetworkInterfaceHelperClient,
|
---|
1194 | static_cast <void *> (d.get()),
|
---|
1195 | progress);
|
---|
1196 |
|
---|
1197 | if (SUCCEEDED(rc))
|
---|
1198 | {
|
---|
1199 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1200 | d.release();
|
---|
1201 |
|
---|
1202 | progress->WaitForCompletion(-1);
|
---|
1203 | }
|
---|
1204 | }
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1210 | #endif
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | int NetIfEnableStaticIpConfigV6(VirtualBox *vBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
|
---|
1214 | {
|
---|
1215 | #ifndef VBOX_WITH_NETFLT
|
---|
1216 | return VERR_NOT_IMPLEMENTED;
|
---|
1217 | #else
|
---|
1218 | HRESULT rc;
|
---|
1219 | Bstr guid;
|
---|
1220 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1221 | if(SUCCEEDED(rc))
|
---|
1222 | {
|
---|
1223 | // ComPtr<VirtualBox> vBox;
|
---|
1224 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1225 | // if(SUCCEEDED(rc))
|
---|
1226 | {
|
---|
1227 | /* create a progress object */
|
---|
1228 | ComObjPtr<Progress> progress;
|
---|
1229 | progress.createObject();
|
---|
1230 | // ComPtr<IHost> host;
|
---|
1231 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1232 | // if(SUCCEEDED(rc))
|
---|
1233 | {
|
---|
1234 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1235 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1236 | FALSE /* aCancelable */);
|
---|
1237 | if(SUCCEEDED(rc))
|
---|
1238 | {
|
---|
1239 | CheckComRCReturnRC(rc);
|
---|
1240 | // progress.queryInterfaceTo(aProgress);
|
---|
1241 |
|
---|
1242 | /* create the networkInterfaceHelperClient() argument */
|
---|
1243 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1244 | d (new NetworkInterfaceHelperClientData());
|
---|
1245 | AssertReturn(d.get(), E_OUTOFMEMORY);
|
---|
1246 |
|
---|
1247 | d->msgCode = SVCHlpMsg::EnableStaticIpConfigV6;
|
---|
1248 | d->guid = guid;
|
---|
1249 | d->iface = pIf;
|
---|
1250 | d->u.StaticIPV6.IPV6Address = aIPV6Address;
|
---|
1251 | d->u.StaticIPV6.IPV6NetMaskLength = aIPV6MaskPrefixLength;
|
---|
1252 |
|
---|
1253 | rc = vBox->startSVCHelperClient (
|
---|
1254 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1255 | netIfNetworkInterfaceHelperClient,
|
---|
1256 | static_cast <void *> (d.get()),
|
---|
1257 | progress);
|
---|
1258 |
|
---|
1259 | if (SUCCEEDED(rc))
|
---|
1260 | {
|
---|
1261 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1262 | d.release();
|
---|
1263 |
|
---|
1264 | progress->WaitForCompletion(-1);
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 | }
|
---|
1268 | }
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1272 | #endif
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | int NetIfEnableDynamicIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf)
|
---|
1276 | {
|
---|
1277 | #ifndef VBOX_WITH_NETFLT
|
---|
1278 | return VERR_NOT_IMPLEMENTED;
|
---|
1279 | #else
|
---|
1280 | HRESULT rc;
|
---|
1281 | Bstr guid;
|
---|
1282 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1283 | if(SUCCEEDED(rc))
|
---|
1284 | {
|
---|
1285 | // ComPtr<VirtualBox> vBox;
|
---|
1286 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1287 | // if(SUCCEEDED(rc))
|
---|
1288 | {
|
---|
1289 | /* create a progress object */
|
---|
1290 | ComObjPtr<Progress> progress;
|
---|
1291 | progress.createObject();
|
---|
1292 | // ComPtr<IHost> host;
|
---|
1293 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1294 | // if(SUCCEEDED(rc))
|
---|
1295 | {
|
---|
1296 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1297 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1298 | FALSE /* aCancelable */);
|
---|
1299 | if(SUCCEEDED(rc))
|
---|
1300 | {
|
---|
1301 | CheckComRCReturnRC(rc);
|
---|
1302 | // progress.queryInterfaceTo(aProgress);
|
---|
1303 |
|
---|
1304 | /* create the networkInterfaceHelperClient() argument */
|
---|
1305 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1306 | d (new NetworkInterfaceHelperClientData());
|
---|
1307 | AssertReturn(d.get(), E_OUTOFMEMORY);
|
---|
1308 |
|
---|
1309 | d->msgCode = SVCHlpMsg::EnableDynamicIpConfig;
|
---|
1310 | d->guid = guid;
|
---|
1311 | d->iface = pIf;
|
---|
1312 |
|
---|
1313 | rc = vBox->startSVCHelperClient (
|
---|
1314 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1315 | netIfNetworkInterfaceHelperClient,
|
---|
1316 | static_cast <void *> (d.get()),
|
---|
1317 | progress);
|
---|
1318 |
|
---|
1319 | if (SUCCEEDED(rc))
|
---|
1320 | {
|
---|
1321 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1322 | d.release();
|
---|
1323 |
|
---|
1324 | progress->WaitForCompletion(-1);
|
---|
1325 | }
|
---|
1326 | }
|
---|
1327 | }
|
---|
1328 | }
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1332 | #endif
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | int NetIfDhcpRediscover(VirtualBox *vBox, HostNetworkInterface * pIf)
|
---|
1336 | {
|
---|
1337 | #ifndef VBOX_WITH_NETFLT
|
---|
1338 | return VERR_NOT_IMPLEMENTED;
|
---|
1339 | #else
|
---|
1340 | HRESULT rc;
|
---|
1341 | Bstr guid;
|
---|
1342 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1343 | if(SUCCEEDED(rc))
|
---|
1344 | {
|
---|
1345 | // ComPtr<VirtualBox> vBox;
|
---|
1346 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1347 | // if(SUCCEEDED(rc))
|
---|
1348 | {
|
---|
1349 | /* create a progress object */
|
---|
1350 | ComObjPtr<Progress> progress;
|
---|
1351 | progress.createObject();
|
---|
1352 | // ComPtr<IHost> host;
|
---|
1353 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1354 | // if(SUCCEEDED(rc))
|
---|
1355 | {
|
---|
1356 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1357 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1358 | FALSE /* aCancelable */);
|
---|
1359 | if(SUCCEEDED(rc))
|
---|
1360 | {
|
---|
1361 | CheckComRCReturnRC(rc);
|
---|
1362 | // progress.queryInterfaceTo(aProgress);
|
---|
1363 |
|
---|
1364 | /* create the networkInterfaceHelperClient() argument */
|
---|
1365 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1366 | d (new NetworkInterfaceHelperClientData());
|
---|
1367 | AssertReturn(d.get(), E_OUTOFMEMORY);
|
---|
1368 |
|
---|
1369 | d->msgCode = SVCHlpMsg::DhcpRediscover;
|
---|
1370 | d->guid = guid;
|
---|
1371 | d->iface = pIf;
|
---|
1372 |
|
---|
1373 | rc = vBox->startSVCHelperClient (
|
---|
1374 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1375 | netIfNetworkInterfaceHelperClient,
|
---|
1376 | static_cast <void *> (d.get()),
|
---|
1377 | progress);
|
---|
1378 |
|
---|
1379 | if (SUCCEEDED(rc))
|
---|
1380 | {
|
---|
1381 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1382 | d.release();
|
---|
1383 |
|
---|
1384 | progress->WaitForCompletion(-1);
|
---|
1385 | }
|
---|
1386 | }
|
---|
1387 | }
|
---|
1388 | }
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1392 | #endif
|
---|
1393 | }
|
---|
1394 |
|
---|
1395 | int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
|
---|
1396 | {
|
---|
1397 | #ifndef VBOX_WITH_NETFLT
|
---|
1398 | return VERR_NOT_IMPLEMENTED;
|
---|
1399 | #else /* # if defined VBOX_WITH_NETFLT */
|
---|
1400 | INetCfg *pNc;
|
---|
1401 | INetCfgComponent *pMpNcc;
|
---|
1402 | INetCfgComponent *pTcpIpNcc;
|
---|
1403 | LPWSTR lpszApp;
|
---|
1404 | HRESULT hr;
|
---|
1405 | IEnumNetCfgBindingPath *pEnumBp;
|
---|
1406 | INetCfgBindingPath *pBp;
|
---|
1407 | IEnumNetCfgBindingInterface *pEnumBi;
|
---|
1408 | INetCfgBindingInterface *pBi;
|
---|
1409 |
|
---|
1410 | /* we are using the INetCfg API for getting the list of miniports */
|
---|
1411 | hr = VBoxNetCfgWinQueryINetCfg( FALSE,
|
---|
1412 | VBOX_APP_NAME,
|
---|
1413 | &pNc,
|
---|
1414 | &lpszApp );
|
---|
1415 | Assert(hr == S_OK);
|
---|
1416 | if(hr == S_OK)
|
---|
1417 | {
|
---|
1418 | # ifdef VBOX_NETFLT_ONDEMAND_BIND
|
---|
1419 | /* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
|
---|
1420 | hr = pNc->FindComponent(L"MS_TCPIP", &pTcpIpNcc);
|
---|
1421 | # else
|
---|
1422 | /* for the filter-based approach we get all miniports our filter (sun_VBoxNetFlt)is bound to */
|
---|
1423 | hr = pNc->FindComponent(L"sun_VBoxNetFlt", &pTcpIpNcc);
|
---|
1424 | # ifndef VBOX_WITH_HARDENING
|
---|
1425 | if(hr != S_OK)
|
---|
1426 | {
|
---|
1427 | /* TODO: try to install the netflt from here */
|
---|
1428 | }
|
---|
1429 | # endif
|
---|
1430 |
|
---|
1431 | # endif
|
---|
1432 |
|
---|
1433 | if(hr == S_OK)
|
---|
1434 | {
|
---|
1435 | hr = VBoxNetCfgWinGetBindingPathEnum(pTcpIpNcc, EBP_BELOW, &pEnumBp);
|
---|
1436 | Assert(hr == S_OK);
|
---|
1437 | if ( hr == S_OK )
|
---|
1438 | {
|
---|
1439 | hr = VBoxNetCfgWinGetFirstBindingPath(pEnumBp, &pBp);
|
---|
1440 | Assert(hr == S_OK || hr == S_FALSE);
|
---|
1441 | while( hr == S_OK )
|
---|
1442 | {
|
---|
1443 | /* S_OK == enabled, S_FALSE == disabled */
|
---|
1444 | if(pBp->IsEnabled() == S_OK)
|
---|
1445 | {
|
---|
1446 | hr = VBoxNetCfgWinGetBindingInterfaceEnum(pBp, &pEnumBi);
|
---|
1447 | Assert(hr == S_OK);
|
---|
1448 | if ( hr == S_OK )
|
---|
1449 | {
|
---|
1450 | hr = VBoxNetCfgWinGetFirstBindingInterface(pEnumBi, &pBi);
|
---|
1451 | Assert(hr == S_OK);
|
---|
1452 | while(hr == S_OK)
|
---|
1453 | {
|
---|
1454 | hr = pBi->GetLowerComponent( &pMpNcc );
|
---|
1455 | Assert(hr == S_OK);
|
---|
1456 | if(hr == S_OK)
|
---|
1457 | {
|
---|
1458 | ULONG uComponentStatus;
|
---|
1459 | hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
|
---|
1460 | //#ifndef DEBUG_bird
|
---|
1461 | // Assert(hr == S_OK);
|
---|
1462 | //#endif
|
---|
1463 | if(hr == S_OK)
|
---|
1464 | {
|
---|
1465 | if(uComponentStatus == 0)
|
---|
1466 | {
|
---|
1467 | vboxNetWinAddComponent(&list, pMpNcc, HostNetworkInterfaceType_Bridged);
|
---|
1468 | }
|
---|
1469 | }
|
---|
1470 | VBoxNetCfgWinReleaseRef( pMpNcc );
|
---|
1471 | }
|
---|
1472 | VBoxNetCfgWinReleaseRef(pBi);
|
---|
1473 |
|
---|
1474 | hr = VBoxNetCfgWinGetNextBindingInterface(pEnumBi, &pBi);
|
---|
1475 | }
|
---|
1476 | VBoxNetCfgWinReleaseRef(pEnumBi);
|
---|
1477 | }
|
---|
1478 | }
|
---|
1479 | VBoxNetCfgWinReleaseRef(pBp);
|
---|
1480 |
|
---|
1481 | hr = VBoxNetCfgWinGetNextBindingPath(pEnumBp, &pBp);
|
---|
1482 | }
|
---|
1483 | VBoxNetCfgWinReleaseRef(pEnumBp);
|
---|
1484 | }
|
---|
1485 | VBoxNetCfgWinReleaseRef(pTcpIpNcc);
|
---|
1486 | }
|
---|
1487 | else
|
---|
1488 | {
|
---|
1489 | LogRel(("failed to get the sun_VBoxNetFlt component, error (0x%x)", hr));
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | netIfListHostAdapters(list);
|
---|
1496 |
|
---|
1497 | return VINF_SUCCESS;
|
---|
1498 | #endif /* # if defined VBOX_WITH_NETFLT */
|
---|
1499 | }
|
---|