VirtualBox

source: vbox/trunk/src/VBox/Main/win/NetIf-win.cpp@ 19160

Last change on this file since 19160 was 19160, checked in by vboxsync, 16 years ago

NetAdp/win: static config fixes for Vista

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette