VirtualBox

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

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

NetIf-win: Assertion not needed here.

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

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