1 | /* $Id: NetIf-win.cpp 19574 2009-05-11 12:14:30Z 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 | AssertReturn (d->name.raw() != NULL, E_POINTER);
|
---|
250 |
|
---|
251 | /* write message and parameters */
|
---|
252 | vrc = aClient->write (d->msgCode);
|
---|
253 | if (RT_FAILURE (vrc)) break;
|
---|
254 | // vrc = aClient->write (Utf8Str (d->name));
|
---|
255 | // if (RT_FAILURE (vrc)) break;
|
---|
256 |
|
---|
257 | /* wait for a reply */
|
---|
258 | bool endLoop = false;
|
---|
259 | while (!endLoop)
|
---|
260 | {
|
---|
261 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
262 |
|
---|
263 | vrc = aClient->read (reply);
|
---|
264 | if (RT_FAILURE (vrc)) break;
|
---|
265 |
|
---|
266 | switch (reply)
|
---|
267 | {
|
---|
268 | case SVCHlpMsg::CreateHostOnlyNetworkInterface_OK:
|
---|
269 | {
|
---|
270 | /* read the GUID */
|
---|
271 | Guid guid;
|
---|
272 | Utf8Str name;
|
---|
273 | vrc = aClient->read (name);
|
---|
274 | if (RT_FAILURE (vrc)) break;
|
---|
275 | vrc = aClient->read (guid);
|
---|
276 | if (RT_FAILURE (vrc)) break;
|
---|
277 |
|
---|
278 | LogFlowFunc (("Network connection GUID = {%RTuuid}, Name = %ls\n", guid.raw(), name.raw()));
|
---|
279 |
|
---|
280 | /* initialize the object returned to the caller by
|
---|
281 | * CreateHostOnlyNetworkInterface() */
|
---|
282 | rc = d->iface->init (Bstr(name), guid, HostNetworkInterfaceType_HostOnly);
|
---|
283 | if(SUCCEEDED(rc))
|
---|
284 | {
|
---|
285 | rc = d->iface->setVirtualBox(d->vBox);
|
---|
286 | if(SUCCEEDED(rc))
|
---|
287 | {
|
---|
288 | rc = d->iface->updateConfig();
|
---|
289 | }
|
---|
290 | }
|
---|
291 | endLoop = true;
|
---|
292 | break;
|
---|
293 | }
|
---|
294 | case SVCHlpMsg::Error:
|
---|
295 | {
|
---|
296 | /* read the error message */
|
---|
297 | Utf8Str errMsg;
|
---|
298 | vrc = aClient->read (errMsg);
|
---|
299 | if (RT_FAILURE (vrc)) break;
|
---|
300 |
|
---|
301 | rc = E_FAIL;//TODO: setError (E_FAIL, errMsg);
|
---|
302 | endLoop = true;
|
---|
303 | break;
|
---|
304 | }
|
---|
305 | default:
|
---|
306 | {
|
---|
307 | endLoop = true;
|
---|
308 | rc = E_FAIL;//TODO: ComAssertMsgFailedBreak ((
|
---|
309 | //"Invalid message code %d (%08lX)\n",
|
---|
310 | //reply, reply),
|
---|
311 | //rc = E_FAIL);
|
---|
312 | }
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | break;
|
---|
317 | }
|
---|
318 | case SVCHlpMsg::RemoveHostOnlyNetworkInterface:
|
---|
319 | {
|
---|
320 | LogFlowFunc (("RemoveHostOnlyNetworkInterface:\n"));
|
---|
321 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", d->guid.raw()));
|
---|
322 |
|
---|
323 | /* write message and parameters */
|
---|
324 | vrc = aClient->write (d->msgCode);
|
---|
325 | if (RT_FAILURE (vrc)) break;
|
---|
326 | vrc = aClient->write (d->guid);
|
---|
327 | if (RT_FAILURE (vrc)) break;
|
---|
328 |
|
---|
329 | /* wait for a reply */
|
---|
330 | bool endLoop = false;
|
---|
331 | while (!endLoop)
|
---|
332 | {
|
---|
333 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
334 |
|
---|
335 | vrc = aClient->read (reply);
|
---|
336 | if (RT_FAILURE (vrc)) break;
|
---|
337 |
|
---|
338 | switch (reply)
|
---|
339 | {
|
---|
340 | case SVCHlpMsg::OK:
|
---|
341 | {
|
---|
342 | /* no parameters */
|
---|
343 | rc = S_OK;
|
---|
344 | endLoop = true;
|
---|
345 | break;
|
---|
346 | }
|
---|
347 | case SVCHlpMsg::Error:
|
---|
348 | {
|
---|
349 | /* read the error message */
|
---|
350 | Utf8Str errMsg;
|
---|
351 | vrc = aClient->read (errMsg);
|
---|
352 | if (RT_FAILURE (vrc)) break;
|
---|
353 |
|
---|
354 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
355 | endLoop = true;
|
---|
356 | break;
|
---|
357 | }
|
---|
358 | default:
|
---|
359 | {
|
---|
360 | endLoop = true;
|
---|
361 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
362 | //"Invalid message code %d (%08lX)\n",
|
---|
363 | //reply, reply),
|
---|
364 | //rc = E_FAIL);
|
---|
365 | }
|
---|
366 | }
|
---|
367 | }
|
---|
368 |
|
---|
369 | break;
|
---|
370 | }
|
---|
371 | case SVCHlpMsg::EnableDynamicIpConfig: /* see usage in code */
|
---|
372 | {
|
---|
373 | LogFlowFunc (("EnableDynamicIpConfig:\n"));
|
---|
374 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
375 |
|
---|
376 | /* write message and parameters */
|
---|
377 | vrc = aClient->write (d->msgCode);
|
---|
378 | if (RT_FAILURE (vrc)) break;
|
---|
379 | vrc = aClient->write (d->guid);
|
---|
380 | if (RT_FAILURE (vrc)) break;
|
---|
381 |
|
---|
382 | /* wait for a reply */
|
---|
383 | bool endLoop = false;
|
---|
384 | while (!endLoop)
|
---|
385 | {
|
---|
386 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
387 |
|
---|
388 | vrc = aClient->read (reply);
|
---|
389 | if (RT_FAILURE (vrc)) break;
|
---|
390 |
|
---|
391 | switch (reply)
|
---|
392 | {
|
---|
393 | case SVCHlpMsg::OK:
|
---|
394 | {
|
---|
395 | /* no parameters */
|
---|
396 | rc = d->iface->updateConfig();
|
---|
397 | endLoop = true;
|
---|
398 | break;
|
---|
399 | }
|
---|
400 | case SVCHlpMsg::Error:
|
---|
401 | {
|
---|
402 | /* read the error message */
|
---|
403 | Utf8Str errMsg;
|
---|
404 | vrc = aClient->read (errMsg);
|
---|
405 | if (RT_FAILURE (vrc)) break;
|
---|
406 |
|
---|
407 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
408 | endLoop = true;
|
---|
409 | break;
|
---|
410 | }
|
---|
411 | default:
|
---|
412 | {
|
---|
413 | endLoop = true;
|
---|
414 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
415 | //"Invalid message code %d (%08lX)\n",
|
---|
416 | //reply, reply),
|
---|
417 | //rc = E_FAIL);
|
---|
418 | }
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | break;
|
---|
423 | }
|
---|
424 | case SVCHlpMsg::EnableStaticIpConfig: /* see usage in code */
|
---|
425 | {
|
---|
426 | LogFlowFunc (("EnableStaticIpConfig:\n"));
|
---|
427 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
428 |
|
---|
429 | /* write message and parameters */
|
---|
430 | vrc = aClient->write (d->msgCode);
|
---|
431 | if (RT_FAILURE (vrc)) break;
|
---|
432 | vrc = aClient->write (d->guid);
|
---|
433 | if (RT_FAILURE (vrc)) break;
|
---|
434 | vrc = aClient->write (d->u.StaticIP.IPAddress);
|
---|
435 | if (RT_FAILURE (vrc)) break;
|
---|
436 | vrc = aClient->write (d->u.StaticIP.IPNetMask);
|
---|
437 | if (RT_FAILURE (vrc)) break;
|
---|
438 |
|
---|
439 | /* wait for a reply */
|
---|
440 | bool endLoop = false;
|
---|
441 | while (!endLoop)
|
---|
442 | {
|
---|
443 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
444 |
|
---|
445 | vrc = aClient->read (reply);
|
---|
446 | if (RT_FAILURE (vrc)) break;
|
---|
447 |
|
---|
448 | switch (reply)
|
---|
449 | {
|
---|
450 | case SVCHlpMsg::OK:
|
---|
451 | {
|
---|
452 | /* no parameters */
|
---|
453 | rc = d->iface->updateConfig();
|
---|
454 | endLoop = true;
|
---|
455 | break;
|
---|
456 | }
|
---|
457 | case SVCHlpMsg::Error:
|
---|
458 | {
|
---|
459 | /* read the error message */
|
---|
460 | Utf8Str errMsg;
|
---|
461 | vrc = aClient->read (errMsg);
|
---|
462 | if (RT_FAILURE (vrc)) break;
|
---|
463 |
|
---|
464 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
465 | endLoop = true;
|
---|
466 | break;
|
---|
467 | }
|
---|
468 | default:
|
---|
469 | {
|
---|
470 | endLoop = true;
|
---|
471 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
472 | //"Invalid message code %d (%08lX)\n",
|
---|
473 | //reply, reply),
|
---|
474 | //rc = E_FAIL);
|
---|
475 | }
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 | break;
|
---|
480 | }
|
---|
481 | case SVCHlpMsg::EnableStaticIpConfigV6: /* see usage in code */
|
---|
482 | {
|
---|
483 | LogFlowFunc (("EnableStaticIpConfigV6:\n"));
|
---|
484 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
485 |
|
---|
486 | /* write message and parameters */
|
---|
487 | vrc = aClient->write (d->msgCode);
|
---|
488 | if (RT_FAILURE (vrc)) break;
|
---|
489 | vrc = aClient->write (d->guid);
|
---|
490 | if (RT_FAILURE (vrc)) break;
|
---|
491 | vrc = aClient->write (Utf8Str(d->u.StaticIPV6.IPV6Address));
|
---|
492 | if (RT_FAILURE (vrc)) break;
|
---|
493 | vrc = aClient->write (d->u.StaticIPV6.IPV6NetMaskLength);
|
---|
494 | if (RT_FAILURE (vrc)) break;
|
---|
495 |
|
---|
496 | /* wait for a reply */
|
---|
497 | bool endLoop = false;
|
---|
498 | while (!endLoop)
|
---|
499 | {
|
---|
500 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
501 |
|
---|
502 | vrc = aClient->read (reply);
|
---|
503 | if (RT_FAILURE (vrc)) break;
|
---|
504 |
|
---|
505 | switch (reply)
|
---|
506 | {
|
---|
507 | case SVCHlpMsg::OK:
|
---|
508 | {
|
---|
509 | /* no parameters */
|
---|
510 | rc = d->iface->updateConfig();
|
---|
511 | endLoop = true;
|
---|
512 | break;
|
---|
513 | }
|
---|
514 | case SVCHlpMsg::Error:
|
---|
515 | {
|
---|
516 | /* read the error message */
|
---|
517 | Utf8Str errMsg;
|
---|
518 | vrc = aClient->read (errMsg);
|
---|
519 | if (RT_FAILURE (vrc)) break;
|
---|
520 |
|
---|
521 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
522 | endLoop = true;
|
---|
523 | break;
|
---|
524 | }
|
---|
525 | default:
|
---|
526 | {
|
---|
527 | endLoop = true;
|
---|
528 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
529 | //"Invalid message code %d (%08lX)\n",
|
---|
530 | //reply, reply),
|
---|
531 | //rc = E_FAIL);
|
---|
532 | }
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | break;
|
---|
537 | }
|
---|
538 | case SVCHlpMsg::DhcpRediscover: /* see usage in code */
|
---|
539 | {
|
---|
540 | LogFlowFunc (("DhcpRediscover:\n"));
|
---|
541 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
542 |
|
---|
543 | /* write message and parameters */
|
---|
544 | vrc = aClient->write (d->msgCode);
|
---|
545 | if (RT_FAILURE (vrc)) break;
|
---|
546 | vrc = aClient->write (d->guid);
|
---|
547 | if (RT_FAILURE (vrc)) break;
|
---|
548 |
|
---|
549 | /* wait for a reply */
|
---|
550 | bool endLoop = false;
|
---|
551 | while (!endLoop)
|
---|
552 | {
|
---|
553 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
554 |
|
---|
555 | vrc = aClient->read (reply);
|
---|
556 | if (RT_FAILURE (vrc)) break;
|
---|
557 |
|
---|
558 | switch (reply)
|
---|
559 | {
|
---|
560 | case SVCHlpMsg::OK:
|
---|
561 | {
|
---|
562 | /* no parameters */
|
---|
563 | rc = d->iface->updateConfig();
|
---|
564 | endLoop = true;
|
---|
565 | break;
|
---|
566 | }
|
---|
567 | case SVCHlpMsg::Error:
|
---|
568 | {
|
---|
569 | /* read the error message */
|
---|
570 | Utf8Str errMsg;
|
---|
571 | vrc = aClient->read (errMsg);
|
---|
572 | if (RT_FAILURE (vrc)) break;
|
---|
573 |
|
---|
574 | rc = E_FAIL; // TODO: setError (E_FAIL, errMsg);
|
---|
575 | endLoop = true;
|
---|
576 | break;
|
---|
577 | }
|
---|
578 | default:
|
---|
579 | {
|
---|
580 | endLoop = true;
|
---|
581 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
582 | //"Invalid message code %d (%08lX)\n",
|
---|
583 | //reply, reply),
|
---|
584 | //rc = E_FAIL);
|
---|
585 | }
|
---|
586 | }
|
---|
587 | }
|
---|
588 |
|
---|
589 | break;
|
---|
590 | }
|
---|
591 | default:
|
---|
592 | rc = E_FAIL; // TODO: ComAssertMsgFailedBreak ((
|
---|
593 | // "Invalid message code %d (%08lX)\n",
|
---|
594 | // d->msgCode, d->msgCode),
|
---|
595 | // rc = E_FAIL);
|
---|
596 | }
|
---|
597 |
|
---|
598 | if (aVrc)
|
---|
599 | *aVrc = vrc;
|
---|
600 |
|
---|
601 | LogFlowFunc (("rc=0x%08X, vrc=%Rrc\n", rc, vrc));
|
---|
602 | LogFlowFuncLeave();
|
---|
603 | return rc;
|
---|
604 | }
|
---|
605 |
|
---|
606 |
|
---|
607 | int netIfNetworkInterfaceHelperServer (SVCHlpClient *aClient,
|
---|
608 | SVCHlpMsg::Code aMsgCode)
|
---|
609 | {
|
---|
610 | LogFlowFuncEnter();
|
---|
611 | LogFlowFunc (("aClient={%p}, aMsgCode=%d\n", aClient, aMsgCode));
|
---|
612 |
|
---|
613 | AssertReturn (aClient, VERR_INVALID_POINTER);
|
---|
614 |
|
---|
615 | int vrc = VINF_SUCCESS;
|
---|
616 | HRESULT hrc;
|
---|
617 |
|
---|
618 | switch (aMsgCode)
|
---|
619 | {
|
---|
620 | case SVCHlpMsg::CreateHostOnlyNetworkInterface:
|
---|
621 | {
|
---|
622 | LogFlowFunc (("CreateHostOnlyNetworkInterface:\n"));
|
---|
623 |
|
---|
624 | // Utf8Str name;
|
---|
625 | // vrc = aClient->read (name);
|
---|
626 | // if (RT_FAILURE (vrc)) break;
|
---|
627 |
|
---|
628 | Guid guid;
|
---|
629 | Utf8Str errMsg;
|
---|
630 | Bstr name;
|
---|
631 | Bstr bstrErr;
|
---|
632 |
|
---|
633 | hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface (guid.asOutParam(), name.asOutParam(), bstrErr.asOutParam());
|
---|
634 |
|
---|
635 | if (hrc == S_OK)
|
---|
636 | {
|
---|
637 | ULONG ip, mask;
|
---|
638 | hrc = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask);
|
---|
639 | if(hrc == S_OK)
|
---|
640 | {
|
---|
641 | /* ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip,
|
---|
642 | * i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter */
|
---|
643 | ip = ip | (1 << 24);
|
---|
644 | hrc = VBoxNetCfgWinEnableStaticIpConfig((const GUID*)guid.raw(), ip, mask);
|
---|
645 | }
|
---|
646 |
|
---|
647 | /* write success followed by GUID */
|
---|
648 | vrc = aClient->write (SVCHlpMsg::CreateHostOnlyNetworkInterface_OK);
|
---|
649 | if (RT_FAILURE (vrc)) break;
|
---|
650 | vrc = aClient->write (Utf8Str (name));
|
---|
651 | if (RT_FAILURE (vrc)) break;
|
---|
652 | vrc = aClient->write (guid);
|
---|
653 | if (RT_FAILURE (vrc)) break;
|
---|
654 | }
|
---|
655 | else
|
---|
656 | {
|
---|
657 | vrc = VERR_GENERAL_FAILURE;
|
---|
658 | errMsg = Utf8Str(bstrErr);
|
---|
659 | /* write failure followed by error message */
|
---|
660 | if (errMsg.isEmpty())
|
---|
661 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
662 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
663 | if (RT_FAILURE (vrc)) break;
|
---|
664 | vrc = aClient->write (errMsg);
|
---|
665 | if (RT_FAILURE (vrc)) break;
|
---|
666 | }
|
---|
667 |
|
---|
668 | break;
|
---|
669 | }
|
---|
670 | case SVCHlpMsg::RemoveHostOnlyNetworkInterface:
|
---|
671 | {
|
---|
672 | LogFlowFunc (("RemoveHostOnlyNetworkInterface:\n"));
|
---|
673 |
|
---|
674 | Guid guid;
|
---|
675 | Bstr bstrErr;
|
---|
676 |
|
---|
677 | vrc = aClient->read (guid);
|
---|
678 | if (RT_FAILURE (vrc)) break;
|
---|
679 |
|
---|
680 | Utf8Str errMsg;
|
---|
681 | hrc = VBoxNetCfgWinRemoveHostOnlyNetworkInterface ((const GUID*)guid.raw(), bstrErr.asOutParam());
|
---|
682 |
|
---|
683 | if (hrc == S_OK)
|
---|
684 | {
|
---|
685 | /* write parameter-less success */
|
---|
686 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
687 | if (RT_FAILURE (vrc)) break;
|
---|
688 | }
|
---|
689 | else
|
---|
690 | {
|
---|
691 | vrc = VERR_GENERAL_FAILURE;
|
---|
692 | errMsg = Utf8Str(bstrErr);
|
---|
693 | /* write failure followed by error message */
|
---|
694 | if (errMsg.isEmpty())
|
---|
695 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
696 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
697 | if (RT_FAILURE (vrc)) break;
|
---|
698 | vrc = aClient->write (errMsg);
|
---|
699 | if (RT_FAILURE (vrc)) break;
|
---|
700 | }
|
---|
701 |
|
---|
702 | break;
|
---|
703 | }
|
---|
704 | case SVCHlpMsg::EnableStaticIpConfigV6:
|
---|
705 | {
|
---|
706 | LogFlowFunc (("EnableStaticIpConfigV6:\n"));
|
---|
707 |
|
---|
708 | Guid guid;
|
---|
709 | Utf8Str ipV6;
|
---|
710 | ULONG maskLengthV6;
|
---|
711 | vrc = aClient->read (guid);
|
---|
712 | if (RT_FAILURE (vrc)) break;
|
---|
713 | vrc = aClient->read (ipV6);
|
---|
714 | if (RT_FAILURE (vrc)) break;
|
---|
715 | vrc = aClient->read (maskLengthV6);
|
---|
716 | if (RT_FAILURE (vrc)) break;
|
---|
717 |
|
---|
718 | Utf8Str errMsg;
|
---|
719 | vrc = VERR_NOT_IMPLEMENTED;
|
---|
720 |
|
---|
721 | if (RT_SUCCESS (vrc))
|
---|
722 | {
|
---|
723 | /* write success followed by GUID */
|
---|
724 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
725 | if (RT_FAILURE (vrc)) break;
|
---|
726 | }
|
---|
727 | else
|
---|
728 | {
|
---|
729 | /* write failure followed by error message */
|
---|
730 | if (errMsg.isEmpty())
|
---|
731 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
732 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
733 | if (RT_FAILURE (vrc)) break;
|
---|
734 | vrc = aClient->write (errMsg);
|
---|
735 | if (RT_FAILURE (vrc)) break;
|
---|
736 | }
|
---|
737 |
|
---|
738 | break;
|
---|
739 | }
|
---|
740 | case SVCHlpMsg::EnableStaticIpConfig:
|
---|
741 | {
|
---|
742 | LogFlowFunc (("EnableStaticIpConfig:\n"));
|
---|
743 |
|
---|
744 | Guid guid;
|
---|
745 | ULONG ip, mask;
|
---|
746 | vrc = aClient->read (guid);
|
---|
747 | if (RT_FAILURE (vrc)) break;
|
---|
748 | vrc = aClient->read (ip);
|
---|
749 | if (RT_FAILURE (vrc)) break;
|
---|
750 | vrc = aClient->read (mask);
|
---|
751 | if (RT_FAILURE (vrc)) break;
|
---|
752 |
|
---|
753 | Utf8Str errMsg;
|
---|
754 | hrc = VBoxNetCfgWinEnableStaticIpConfig ((const GUID *)guid.raw(), ip, mask);
|
---|
755 |
|
---|
756 | if (hrc == S_OK)
|
---|
757 | {
|
---|
758 | /* write success followed by GUID */
|
---|
759 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
760 | if (RT_FAILURE (vrc)) break;
|
---|
761 | }
|
---|
762 | else
|
---|
763 | {
|
---|
764 | vrc = VERR_GENERAL_FAILURE;
|
---|
765 | /* write failure followed by error message */
|
---|
766 | if (errMsg.isEmpty())
|
---|
767 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
768 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
769 | if (RT_FAILURE (vrc)) break;
|
---|
770 | vrc = aClient->write (errMsg);
|
---|
771 | if (RT_FAILURE (vrc)) break;
|
---|
772 | }
|
---|
773 |
|
---|
774 | break;
|
---|
775 | }
|
---|
776 | case SVCHlpMsg::EnableDynamicIpConfig:
|
---|
777 | {
|
---|
778 | LogFlowFunc (("EnableDynamicIpConfig:\n"));
|
---|
779 |
|
---|
780 | Guid guid;
|
---|
781 | vrc = aClient->read (guid);
|
---|
782 | if (RT_FAILURE (vrc)) break;
|
---|
783 |
|
---|
784 | Utf8Str errMsg;
|
---|
785 | hrc = VBoxNetCfgWinEnableDynamicIpConfig ((const GUID *)guid.raw());
|
---|
786 |
|
---|
787 | if (hrc == S_OK)
|
---|
788 | {
|
---|
789 | /* write success followed by GUID */
|
---|
790 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
791 | if (RT_FAILURE (vrc)) break;
|
---|
792 | }
|
---|
793 | else
|
---|
794 | {
|
---|
795 | vrc = VERR_GENERAL_FAILURE;
|
---|
796 | /* write failure followed by error message */
|
---|
797 | if (errMsg.isEmpty())
|
---|
798 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
799 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
800 | if (RT_FAILURE (vrc)) break;
|
---|
801 | vrc = aClient->write (errMsg);
|
---|
802 | if (RT_FAILURE (vrc)) break;
|
---|
803 | }
|
---|
804 |
|
---|
805 | break;
|
---|
806 | }
|
---|
807 | case SVCHlpMsg::DhcpRediscover:
|
---|
808 | {
|
---|
809 | LogFlowFunc (("DhcpRediscover:\n"));
|
---|
810 |
|
---|
811 | Guid guid;
|
---|
812 | vrc = aClient->read (guid);
|
---|
813 | if (RT_FAILURE (vrc)) break;
|
---|
814 |
|
---|
815 | Utf8Str errMsg;
|
---|
816 | hrc = VBoxNetCfgWinDhcpRediscover ((const GUID *)guid.raw());
|
---|
817 |
|
---|
818 | if (hrc == S_OK)
|
---|
819 | {
|
---|
820 | /* write success followed by GUID */
|
---|
821 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
822 | if (RT_FAILURE (vrc)) break;
|
---|
823 | }
|
---|
824 | else
|
---|
825 | {
|
---|
826 | vrc = VERR_GENERAL_FAILURE;
|
---|
827 | /* write failure followed by error message */
|
---|
828 | if (errMsg.isEmpty())
|
---|
829 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
830 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
831 | if (RT_FAILURE (vrc)) break;
|
---|
832 | vrc = aClient->write (errMsg);
|
---|
833 | if (RT_FAILURE (vrc)) break;
|
---|
834 | }
|
---|
835 |
|
---|
836 | break;
|
---|
837 | }
|
---|
838 | default:
|
---|
839 | AssertMsgFailedBreakStmt (
|
---|
840 | ("Invalid message code %d (%08lX)\n", aMsgCode, aMsgCode),
|
---|
841 | VERR_GENERAL_FAILURE);
|
---|
842 | }
|
---|
843 |
|
---|
844 | LogFlowFunc (("vrc=%Rrc\n", vrc));
|
---|
845 | LogFlowFuncLeave();
|
---|
846 | return vrc;
|
---|
847 | }
|
---|
848 |
|
---|
849 | /** @todo REMOVE. OBSOLETE NOW. */
|
---|
850 | /**
|
---|
851 | * Returns TRUE if the Windows version is 6.0 or greater (i.e. it's Vista and
|
---|
852 | * later OSes) and it has the UAC (User Account Control) feature enabled.
|
---|
853 | */
|
---|
854 | static BOOL IsUACEnabled()
|
---|
855 | {
|
---|
856 | LONG rc = 0;
|
---|
857 |
|
---|
858 | OSVERSIONINFOEX info;
|
---|
859 | ZeroMemory (&info, sizeof (OSVERSIONINFOEX));
|
---|
860 | info.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
|
---|
861 | rc = GetVersionEx ((OSVERSIONINFO *) &info);
|
---|
862 | AssertReturn (rc != 0, FALSE);
|
---|
863 |
|
---|
864 | LogFlowFunc (("dwMajorVersion=%d, dwMinorVersion=%d\n",
|
---|
865 | info.dwMajorVersion, info.dwMinorVersion));
|
---|
866 |
|
---|
867 | /* we are interested only in Vista (and newer versions...). In all
|
---|
868 | * earlier versions UAC is not present. */
|
---|
869 | if (info.dwMajorVersion < 6)
|
---|
870 | return FALSE;
|
---|
871 |
|
---|
872 | /* the default EnableLUA value is 1 (Enabled) */
|
---|
873 | DWORD dwEnableLUA = 1;
|
---|
874 |
|
---|
875 | HKEY hKey;
|
---|
876 | rc = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
|
---|
877 | "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
|
---|
878 | 0, KEY_QUERY_VALUE, &hKey);
|
---|
879 |
|
---|
880 | Assert (rc == ERROR_SUCCESS || rc == ERROR_PATH_NOT_FOUND);
|
---|
881 | if (rc == ERROR_SUCCESS)
|
---|
882 | {
|
---|
883 |
|
---|
884 | DWORD cbEnableLUA = sizeof (dwEnableLUA);
|
---|
885 | rc = RegQueryValueExA (hKey, "EnableLUA", NULL, NULL,
|
---|
886 | (LPBYTE) &dwEnableLUA, &cbEnableLUA);
|
---|
887 |
|
---|
888 | RegCloseKey (hKey);
|
---|
889 |
|
---|
890 | Assert (rc == ERROR_SUCCESS || rc == ERROR_FILE_NOT_FOUND);
|
---|
891 | }
|
---|
892 |
|
---|
893 | LogFlowFunc (("rc=%d, dwEnableLUA=%d\n", rc, dwEnableLUA));
|
---|
894 |
|
---|
895 | return dwEnableLUA == 1;
|
---|
896 | }
|
---|
897 |
|
---|
898 | /* end */
|
---|
899 |
|
---|
900 | static int vboxNetWinAddComponent(std::list <ComObjPtr <HostNetworkInterface> > * pPist, INetCfgComponent * pncc, HostNetworkInterfaceType enmType)
|
---|
901 | {
|
---|
902 | LPWSTR lpszName;
|
---|
903 | GUID IfGuid;
|
---|
904 | HRESULT hr;
|
---|
905 | int rc = VERR_GENERAL_FAILURE;
|
---|
906 |
|
---|
907 | hr = pncc->GetDisplayName( &lpszName );
|
---|
908 | Assert(hr == S_OK);
|
---|
909 | if(hr == S_OK)
|
---|
910 | {
|
---|
911 | size_t cUnicodeName = wcslen(lpszName) + 1;
|
---|
912 | size_t uniLen = (cUnicodeName * 2 + sizeof (OLECHAR) - 1) / sizeof (OLECHAR);
|
---|
913 | Bstr name (uniLen + 1 /* extra zero */);
|
---|
914 | wcscpy((wchar_t *) name.mutableRaw(), lpszName);
|
---|
915 |
|
---|
916 | hr = pncc->GetInstanceGuid(&IfGuid);
|
---|
917 | Assert(hr == S_OK);
|
---|
918 | if (hr == S_OK)
|
---|
919 | {
|
---|
920 | NETIFINFO Info;
|
---|
921 | memset(&Info, 0, sizeof(Info));
|
---|
922 | Info.Uuid = *(Guid(IfGuid).raw());
|
---|
923 | rc = collectNetIfInfo(name, Guid(IfGuid), &Info);
|
---|
924 | if (RT_FAILURE(rc))
|
---|
925 | {
|
---|
926 | Log(("vboxNetWinAddComponent: collectNetIfInfo() -> %Vrc\n", rc));
|
---|
927 | }
|
---|
928 | /* create a new object and add it to the list */
|
---|
929 | ComObjPtr <HostNetworkInterface> iface;
|
---|
930 | iface.createObject();
|
---|
931 | /* remove the curly bracket at the end */
|
---|
932 | if (SUCCEEDED (iface->init (name, enmType, &Info)))
|
---|
933 | {
|
---|
934 | pPist->push_back (iface);
|
---|
935 | rc = VINF_SUCCESS;
|
---|
936 | }
|
---|
937 | else
|
---|
938 | {
|
---|
939 | Assert(0);
|
---|
940 | }
|
---|
941 | }
|
---|
942 | CoTaskMemFree(lpszName);
|
---|
943 | }
|
---|
944 |
|
---|
945 | return rc;
|
---|
946 | }
|
---|
947 |
|
---|
948 | #endif /* VBOX_WITH_NETFLT */
|
---|
949 |
|
---|
950 |
|
---|
951 | static int netIfListHostAdapters(std::list <ComObjPtr <HostNetworkInterface> > &list)
|
---|
952 | {
|
---|
953 | #ifndef VBOX_WITH_NETFLT
|
---|
954 | /* VBoxNetAdp is available only when VBOX_WITH_NETFLT is enabled */
|
---|
955 | return VERR_NOT_IMPLEMENTED;
|
---|
956 | #else /* # if defined VBOX_WITH_NETFLT */
|
---|
957 | INetCfg *pNc;
|
---|
958 | INetCfgComponent *pMpNcc;
|
---|
959 | LPWSTR lpszApp = NULL;
|
---|
960 | HRESULT hr;
|
---|
961 | IEnumNetCfgComponent *pEnumComponent;
|
---|
962 |
|
---|
963 | /* we are using the INetCfg API for getting the list of miniports */
|
---|
964 | hr = VBoxNetCfgWinQueryINetCfg( FALSE,
|
---|
965 | VBOX_APP_NAME,
|
---|
966 | &pNc,
|
---|
967 | &lpszApp );
|
---|
968 | Assert(hr == S_OK);
|
---|
969 | if(hr == S_OK)
|
---|
970 | {
|
---|
971 | hr = VBoxNetCfgWinGetComponentEnum(pNc, &GUID_DEVCLASS_NET, &pEnumComponent);
|
---|
972 | if(hr == S_OK)
|
---|
973 | {
|
---|
974 | while((hr = VBoxNetCfgWinGetNextComponent(pEnumComponent, &pMpNcc)) == S_OK)
|
---|
975 | {
|
---|
976 | ULONG uComponentStatus;
|
---|
977 | hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
|
---|
978 | //#ifndef DEBUG_bird
|
---|
979 | // Assert(hr == S_OK);
|
---|
980 | //#endif
|
---|
981 | if(hr == S_OK)
|
---|
982 | {
|
---|
983 | if(uComponentStatus == 0)
|
---|
984 | {
|
---|
985 | LPWSTR pId;
|
---|
986 | hr = pMpNcc->GetId(&pId);
|
---|
987 | Assert(hr == S_OK);
|
---|
988 | if(hr == S_OK)
|
---|
989 | {
|
---|
990 | if(!_wcsnicmp(pId, L"sun_VBoxNetAdp", sizeof(L"sun_VBoxNetAdp")/2))
|
---|
991 | {
|
---|
992 | vboxNetWinAddComponent(&list, pMpNcc, HostNetworkInterfaceType_HostOnly);
|
---|
993 | }
|
---|
994 | CoTaskMemFree(pId);
|
---|
995 | }
|
---|
996 | }
|
---|
997 | }
|
---|
998 | VBoxNetCfgWinReleaseRef(pMpNcc);
|
---|
999 | }
|
---|
1000 | Assert(hr == S_OK || hr == S_FALSE);
|
---|
1001 |
|
---|
1002 | VBoxNetCfgWinReleaseRef(pEnumComponent);
|
---|
1003 | }
|
---|
1004 | else
|
---|
1005 | {
|
---|
1006 | LogRel(("failed to get the sun_VBoxNetFlt component, error (0x%x)", hr));
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
|
---|
1010 | }
|
---|
1011 | else if(lpszApp)
|
---|
1012 | {
|
---|
1013 | CoTaskMemFree(lpszApp);
|
---|
1014 | }
|
---|
1015 | #endif /* # if defined VBOX_WITH_NETFLT */
|
---|
1016 | return VINF_SUCCESS;
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *pInfo)
|
---|
1020 | {
|
---|
1021 | #ifndef VBOX_WITH_NETFLT
|
---|
1022 | return VERR_NOT_IMPLEMENTED;
|
---|
1023 | #else
|
---|
1024 | Bstr name;
|
---|
1025 | HRESULT hr = pIf->COMGETTER(Name)(name.asOutParam());
|
---|
1026 | if(hr == S_OK)
|
---|
1027 | {
|
---|
1028 | Bstr IfGuid;
|
---|
1029 | hr = pIf->COMGETTER(Id)(IfGuid.asOutParam());
|
---|
1030 | Assert(hr == S_OK);
|
---|
1031 | if (hr == S_OK)
|
---|
1032 | {
|
---|
1033 | memset(pInfo, 0, sizeof(NETIFINFO));
|
---|
1034 | Guid guid(IfGuid);
|
---|
1035 | pInfo->Uuid = *(guid.raw());
|
---|
1036 |
|
---|
1037 | return collectNetIfInfo(name, guid, pInfo);
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 | return VERR_GENERAL_FAILURE;
|
---|
1041 | #endif
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | int NetIfGetConfigByName(PNETIFINFO)
|
---|
1045 | {
|
---|
1046 | return VERR_NOT_IMPLEMENTED;
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox,
|
---|
1050 | IHostNetworkInterface **aHostNetworkInterface,
|
---|
1051 | IProgress **aProgress)
|
---|
1052 | {
|
---|
1053 | #ifndef VBOX_WITH_NETFLT
|
---|
1054 | return VERR_NOT_IMPLEMENTED;
|
---|
1055 | #else
|
---|
1056 | /* create a progress object */
|
---|
1057 | ComObjPtr <Progress> progress;
|
---|
1058 | progress.createObject();
|
---|
1059 |
|
---|
1060 | ComPtr<IHost> host;
|
---|
1061 | HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());
|
---|
1062 | if(SUCCEEDED(rc))
|
---|
1063 | {
|
---|
1064 | rc = progress->init (pVBox, host,
|
---|
1065 | Bstr (_T ("Creating host only network interface")),
|
---|
1066 | FALSE /* aCancelable */);
|
---|
1067 | if(SUCCEEDED(rc))
|
---|
1068 | {
|
---|
1069 | CheckComRCReturnRC (rc);
|
---|
1070 | progress.queryInterfaceTo (aProgress);
|
---|
1071 |
|
---|
1072 | /* create a new uninitialized host interface object */
|
---|
1073 | ComObjPtr <HostNetworkInterface> iface;
|
---|
1074 | iface.createObject();
|
---|
1075 | iface.queryInterfaceTo (aHostNetworkInterface);
|
---|
1076 |
|
---|
1077 | /* create the networkInterfaceHelperClient() argument */
|
---|
1078 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1079 | d (new NetworkInterfaceHelperClientData());
|
---|
1080 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
1081 |
|
---|
1082 | d->msgCode = SVCHlpMsg::CreateHostOnlyNetworkInterface;
|
---|
1083 | // d->name = aName;
|
---|
1084 | d->iface = iface;
|
---|
1085 | d->vBox = pVBox;
|
---|
1086 |
|
---|
1087 | rc = pVBox->startSVCHelperClient (
|
---|
1088 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1089 | netIfNetworkInterfaceHelperClient,
|
---|
1090 | static_cast <void *> (d.get()),
|
---|
1091 | progress);
|
---|
1092 |
|
---|
1093 | if (SUCCEEDED (rc))
|
---|
1094 | {
|
---|
1095 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1096 | d.release();
|
---|
1097 | }
|
---|
1098 | }
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1102 | #endif
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId,
|
---|
1106 | IHostNetworkInterface **aHostNetworkInterface,
|
---|
1107 | IProgress **aProgress)
|
---|
1108 | {
|
---|
1109 | #ifndef VBOX_WITH_NETFLT
|
---|
1110 | return VERR_NOT_IMPLEMENTED;
|
---|
1111 | #else
|
---|
1112 | /* create a progress object */
|
---|
1113 | ComObjPtr <Progress> progress;
|
---|
1114 | progress.createObject();
|
---|
1115 | ComPtr<IHost> host;
|
---|
1116 | HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());
|
---|
1117 | if(SUCCEEDED(rc))
|
---|
1118 | {
|
---|
1119 | rc = progress->init (pVBox, host,
|
---|
1120 | Bstr (_T ("Removing host network interface")),
|
---|
1121 | FALSE /* aCancelable */);
|
---|
1122 | if(SUCCEEDED(rc))
|
---|
1123 | {
|
---|
1124 | CheckComRCReturnRC (rc);
|
---|
1125 | progress.queryInterfaceTo (aProgress);
|
---|
1126 |
|
---|
1127 | /* create the networkInterfaceHelperClient() argument */
|
---|
1128 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1129 | d (new NetworkInterfaceHelperClientData());
|
---|
1130 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
1131 |
|
---|
1132 | d->msgCode = SVCHlpMsg::RemoveHostOnlyNetworkInterface;
|
---|
1133 | d->guid = aId;
|
---|
1134 |
|
---|
1135 | rc = pVBox->startSVCHelperClient (
|
---|
1136 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1137 | netIfNetworkInterfaceHelperClient,
|
---|
1138 | static_cast <void *> (d.get()),
|
---|
1139 | progress);
|
---|
1140 |
|
---|
1141 | if (SUCCEEDED (rc))
|
---|
1142 | {
|
---|
1143 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1144 | d.release();
|
---|
1145 | }
|
---|
1146 | }
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1150 | #endif
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | int NetIfEnableStaticIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf, ULONG aOldIp, ULONG ip, ULONG mask)
|
---|
1154 | {
|
---|
1155 | #ifndef VBOX_WITH_NETFLT
|
---|
1156 | return VERR_NOT_IMPLEMENTED;
|
---|
1157 | #else
|
---|
1158 | HRESULT rc;
|
---|
1159 | Bstr guid;
|
---|
1160 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1161 | if(SUCCEEDED(rc))
|
---|
1162 | {
|
---|
1163 | // ComPtr<VirtualBox> vBox;
|
---|
1164 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1165 | // if(SUCCEEDED(rc))
|
---|
1166 | {
|
---|
1167 | /* create a progress object */
|
---|
1168 | ComObjPtr <Progress> progress;
|
---|
1169 | progress.createObject();
|
---|
1170 | // ComPtr<IHost> host;
|
---|
1171 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1172 | // if(SUCCEEDED(rc))
|
---|
1173 | {
|
---|
1174 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1175 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1176 | FALSE /* aCancelable */);
|
---|
1177 | if(SUCCEEDED(rc))
|
---|
1178 | {
|
---|
1179 | CheckComRCReturnRC (rc);
|
---|
1180 | // progress.queryInterfaceTo (aProgress);
|
---|
1181 |
|
---|
1182 | /* create the networkInterfaceHelperClient() argument */
|
---|
1183 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1184 | d (new NetworkInterfaceHelperClientData());
|
---|
1185 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
1186 |
|
---|
1187 | d->msgCode = SVCHlpMsg::EnableStaticIpConfig;
|
---|
1188 | d->guid = Guid(guid);
|
---|
1189 | d->iface = pIf;
|
---|
1190 | d->u.StaticIP.IPAddress = ip;
|
---|
1191 | d->u.StaticIP.IPNetMask = mask;
|
---|
1192 |
|
---|
1193 | rc = vBox->startSVCHelperClient (
|
---|
1194 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1195 | netIfNetworkInterfaceHelperClient,
|
---|
1196 | static_cast <void *> (d.get()),
|
---|
1197 | progress);
|
---|
1198 |
|
---|
1199 | if (SUCCEEDED (rc))
|
---|
1200 | {
|
---|
1201 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1202 | d.release();
|
---|
1203 |
|
---|
1204 | progress->WaitForCompletion(-1);
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 | }
|
---|
1208 | }
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1212 | #endif
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | int NetIfEnableStaticIpConfigV6(VirtualBox *vBox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
|
---|
1216 | {
|
---|
1217 | #ifndef VBOX_WITH_NETFLT
|
---|
1218 | return VERR_NOT_IMPLEMENTED;
|
---|
1219 | #else
|
---|
1220 | HRESULT rc;
|
---|
1221 | Bstr guid;
|
---|
1222 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1223 | if(SUCCEEDED(rc))
|
---|
1224 | {
|
---|
1225 | // ComPtr<VirtualBox> vBox;
|
---|
1226 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1227 | // if(SUCCEEDED(rc))
|
---|
1228 | {
|
---|
1229 | /* create a progress object */
|
---|
1230 | ComObjPtr <Progress> progress;
|
---|
1231 | progress.createObject();
|
---|
1232 | // ComPtr<IHost> host;
|
---|
1233 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1234 | // if(SUCCEEDED(rc))
|
---|
1235 | {
|
---|
1236 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1237 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1238 | FALSE /* aCancelable */);
|
---|
1239 | if(SUCCEEDED(rc))
|
---|
1240 | {
|
---|
1241 | CheckComRCReturnRC (rc);
|
---|
1242 | // progress.queryInterfaceTo (aProgress);
|
---|
1243 |
|
---|
1244 | /* create the networkInterfaceHelperClient() argument */
|
---|
1245 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1246 | d (new NetworkInterfaceHelperClientData());
|
---|
1247 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
1248 |
|
---|
1249 | d->msgCode = SVCHlpMsg::EnableStaticIpConfigV6;
|
---|
1250 | d->guid = guid;
|
---|
1251 | d->iface = pIf;
|
---|
1252 | d->u.StaticIPV6.IPV6Address = aIPV6Address;
|
---|
1253 | d->u.StaticIPV6.IPV6NetMaskLength = aIPV6MaskPrefixLength;
|
---|
1254 |
|
---|
1255 | rc = vBox->startSVCHelperClient (
|
---|
1256 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1257 | netIfNetworkInterfaceHelperClient,
|
---|
1258 | static_cast <void *> (d.get()),
|
---|
1259 | progress);
|
---|
1260 |
|
---|
1261 | if (SUCCEEDED (rc))
|
---|
1262 | {
|
---|
1263 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1264 | d.release();
|
---|
1265 |
|
---|
1266 | progress->WaitForCompletion(-1);
|
---|
1267 | }
|
---|
1268 | }
|
---|
1269 | }
|
---|
1270 | }
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1274 | #endif
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | int NetIfEnableDynamicIpConfig(VirtualBox *vBox, HostNetworkInterface * pIf)
|
---|
1278 | {
|
---|
1279 | #ifndef VBOX_WITH_NETFLT
|
---|
1280 | return VERR_NOT_IMPLEMENTED;
|
---|
1281 | #else
|
---|
1282 | HRESULT rc;
|
---|
1283 | Bstr guid;
|
---|
1284 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1285 | if(SUCCEEDED(rc))
|
---|
1286 | {
|
---|
1287 | // ComPtr<VirtualBox> vBox;
|
---|
1288 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1289 | // if(SUCCEEDED(rc))
|
---|
1290 | {
|
---|
1291 | /* create a progress object */
|
---|
1292 | ComObjPtr <Progress> progress;
|
---|
1293 | progress.createObject();
|
---|
1294 | // ComPtr<IHost> host;
|
---|
1295 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1296 | // if(SUCCEEDED(rc))
|
---|
1297 | {
|
---|
1298 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1299 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1300 | FALSE /* aCancelable */);
|
---|
1301 | if(SUCCEEDED(rc))
|
---|
1302 | {
|
---|
1303 | CheckComRCReturnRC (rc);
|
---|
1304 | // progress.queryInterfaceTo (aProgress);
|
---|
1305 |
|
---|
1306 | /* create the networkInterfaceHelperClient() argument */
|
---|
1307 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1308 | d (new NetworkInterfaceHelperClientData());
|
---|
1309 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
1310 |
|
---|
1311 | d->msgCode = SVCHlpMsg::EnableDynamicIpConfig;
|
---|
1312 | d->guid = guid;
|
---|
1313 | d->iface = pIf;
|
---|
1314 |
|
---|
1315 | rc = vBox->startSVCHelperClient (
|
---|
1316 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1317 | netIfNetworkInterfaceHelperClient,
|
---|
1318 | static_cast <void *> (d.get()),
|
---|
1319 | progress);
|
---|
1320 |
|
---|
1321 | if (SUCCEEDED (rc))
|
---|
1322 | {
|
---|
1323 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1324 | d.release();
|
---|
1325 |
|
---|
1326 | progress->WaitForCompletion(-1);
|
---|
1327 | }
|
---|
1328 | }
|
---|
1329 | }
|
---|
1330 | }
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1334 | #endif
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | int NetIfDhcpRediscover(VirtualBox *vBox, HostNetworkInterface * pIf)
|
---|
1338 | {
|
---|
1339 | #ifndef VBOX_WITH_NETFLT
|
---|
1340 | return VERR_NOT_IMPLEMENTED;
|
---|
1341 | #else
|
---|
1342 | HRESULT rc;
|
---|
1343 | Bstr guid;
|
---|
1344 | rc = pIf->COMGETTER(Id) (guid.asOutParam());
|
---|
1345 | if(SUCCEEDED(rc))
|
---|
1346 | {
|
---|
1347 | // ComPtr<VirtualBox> vBox;
|
---|
1348 | // rc = pIf->getVirtualBox (vBox.asOutParam());
|
---|
1349 | // if(SUCCEEDED(rc))
|
---|
1350 | {
|
---|
1351 | /* create a progress object */
|
---|
1352 | ComObjPtr <Progress> progress;
|
---|
1353 | progress.createObject();
|
---|
1354 | // ComPtr<IHost> host;
|
---|
1355 | // HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam());
|
---|
1356 | // if(SUCCEEDED(rc))
|
---|
1357 | {
|
---|
1358 | rc = progress->init (vBox, (IHostNetworkInterface*)pIf,
|
---|
1359 | Bstr ("Enabling Dynamic Ip Configuration"),
|
---|
1360 | FALSE /* aCancelable */);
|
---|
1361 | if(SUCCEEDED(rc))
|
---|
1362 | {
|
---|
1363 | CheckComRCReturnRC (rc);
|
---|
1364 | // progress.queryInterfaceTo (aProgress);
|
---|
1365 |
|
---|
1366 | /* create the networkInterfaceHelperClient() argument */
|
---|
1367 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
1368 | d (new NetworkInterfaceHelperClientData());
|
---|
1369 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
1370 |
|
---|
1371 | d->msgCode = SVCHlpMsg::DhcpRediscover;
|
---|
1372 | d->guid = guid;
|
---|
1373 | d->iface = pIf;
|
---|
1374 |
|
---|
1375 | rc = vBox->startSVCHelperClient (
|
---|
1376 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
1377 | netIfNetworkInterfaceHelperClient,
|
---|
1378 | static_cast <void *> (d.get()),
|
---|
1379 | progress);
|
---|
1380 |
|
---|
1381 | if (SUCCEEDED (rc))
|
---|
1382 | {
|
---|
1383 | /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */
|
---|
1384 | d.release();
|
---|
1385 |
|
---|
1386 | progress->WaitForCompletion(-1);
|
---|
1387 | }
|
---|
1388 | }
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
|
---|
1394 | #endif
|
---|
1395 | }
|
---|
1396 |
|
---|
1397 | int NetIfList(std::list <ComObjPtr <HostNetworkInterface> > &list)
|
---|
1398 | {
|
---|
1399 | #ifndef VBOX_WITH_NETFLT
|
---|
1400 | return VERR_NOT_IMPLEMENTED;
|
---|
1401 | #else /* # if defined VBOX_WITH_NETFLT */
|
---|
1402 | INetCfg *pNc;
|
---|
1403 | INetCfgComponent *pMpNcc;
|
---|
1404 | INetCfgComponent *pTcpIpNcc;
|
---|
1405 | LPWSTR lpszApp;
|
---|
1406 | HRESULT hr;
|
---|
1407 | IEnumNetCfgBindingPath *pEnumBp;
|
---|
1408 | INetCfgBindingPath *pBp;
|
---|
1409 | IEnumNetCfgBindingInterface *pEnumBi;
|
---|
1410 | INetCfgBindingInterface *pBi;
|
---|
1411 |
|
---|
1412 | /* we are using the INetCfg API for getting the list of miniports */
|
---|
1413 | hr = VBoxNetCfgWinQueryINetCfg( FALSE,
|
---|
1414 | VBOX_APP_NAME,
|
---|
1415 | &pNc,
|
---|
1416 | &lpszApp );
|
---|
1417 | Assert(hr == S_OK);
|
---|
1418 | if(hr == S_OK)
|
---|
1419 | {
|
---|
1420 | # ifdef VBOX_NETFLT_ONDEMAND_BIND
|
---|
1421 | /* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
|
---|
1422 | hr = pNc->FindComponent(L"MS_TCPIP", &pTcpIpNcc);
|
---|
1423 | # else
|
---|
1424 | /* for the filter-based approach we get all miniports our filter (sun_VBoxNetFlt)is bound to */
|
---|
1425 | hr = pNc->FindComponent(L"sun_VBoxNetFlt", &pTcpIpNcc);
|
---|
1426 | # ifndef VBOX_WITH_HARDENING
|
---|
1427 | if(hr != S_OK)
|
---|
1428 | {
|
---|
1429 | /* TODO: try to install the netflt from here */
|
---|
1430 | }
|
---|
1431 | # endif
|
---|
1432 |
|
---|
1433 | # endif
|
---|
1434 |
|
---|
1435 | if(hr == S_OK)
|
---|
1436 | {
|
---|
1437 | hr = VBoxNetCfgWinGetBindingPathEnum(pTcpIpNcc, EBP_BELOW, &pEnumBp);
|
---|
1438 | Assert(hr == S_OK);
|
---|
1439 | if ( hr == S_OK )
|
---|
1440 | {
|
---|
1441 | hr = VBoxNetCfgWinGetFirstBindingPath(pEnumBp, &pBp);
|
---|
1442 | Assert(hr == S_OK || hr == S_FALSE);
|
---|
1443 | while( hr == S_OK )
|
---|
1444 | {
|
---|
1445 | /* S_OK == enabled, S_FALSE == disabled */
|
---|
1446 | if(pBp->IsEnabled() == S_OK)
|
---|
1447 | {
|
---|
1448 | hr = VBoxNetCfgWinGetBindingInterfaceEnum(pBp, &pEnumBi);
|
---|
1449 | Assert(hr == S_OK);
|
---|
1450 | if ( hr == S_OK )
|
---|
1451 | {
|
---|
1452 | hr = VBoxNetCfgWinGetFirstBindingInterface(pEnumBi, &pBi);
|
---|
1453 | Assert(hr == S_OK);
|
---|
1454 | while(hr == S_OK)
|
---|
1455 | {
|
---|
1456 | hr = pBi->GetLowerComponent( &pMpNcc );
|
---|
1457 | Assert(hr == S_OK);
|
---|
1458 | if(hr == S_OK)
|
---|
1459 | {
|
---|
1460 | ULONG uComponentStatus;
|
---|
1461 | hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
|
---|
1462 | //#ifndef DEBUG_bird
|
---|
1463 | // Assert(hr == S_OK);
|
---|
1464 | //#endif
|
---|
1465 | if(hr == S_OK)
|
---|
1466 | {
|
---|
1467 | if(uComponentStatus == 0)
|
---|
1468 | {
|
---|
1469 | vboxNetWinAddComponent(&list, pMpNcc, HostNetworkInterfaceType_Bridged);
|
---|
1470 | }
|
---|
1471 | }
|
---|
1472 | VBoxNetCfgWinReleaseRef( pMpNcc );
|
---|
1473 | }
|
---|
1474 | VBoxNetCfgWinReleaseRef(pBi);
|
---|
1475 |
|
---|
1476 | hr = VBoxNetCfgWinGetNextBindingInterface(pEnumBi, &pBi);
|
---|
1477 | }
|
---|
1478 | VBoxNetCfgWinReleaseRef(pEnumBi);
|
---|
1479 | }
|
---|
1480 | }
|
---|
1481 | VBoxNetCfgWinReleaseRef(pBp);
|
---|
1482 |
|
---|
1483 | hr = VBoxNetCfgWinGetNextBindingPath(pEnumBp, &pBp);
|
---|
1484 | }
|
---|
1485 | VBoxNetCfgWinReleaseRef(pEnumBp);
|
---|
1486 | }
|
---|
1487 | VBoxNetCfgWinReleaseRef(pTcpIpNcc);
|
---|
1488 | }
|
---|
1489 | else
|
---|
1490 | {
|
---|
1491 | LogRel(("failed to get the sun_VBoxNetFlt component, error (0x%x)", hr));
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
|
---|
1495 | }
|
---|
1496 |
|
---|
1497 | netIfListHostAdapters(list);
|
---|
1498 |
|
---|
1499 | return VINF_SUCCESS;
|
---|
1500 | #endif /* # if defined VBOX_WITH_NETFLT */
|
---|
1501 | }
|
---|