VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp@ 83432

Last change on this file since 83432 was 83169, checked in by vboxsync, 5 years ago

OCI: (bugref:9469) cloud network integration multiple targets and configuration support (enabled in Config.kmk).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 73.0 KB
Line 
1/* $Id: VBoxManageList.cpp 83169 2020-02-27 09:28:41Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
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
18#ifndef VBOX_ONLY_DOCS
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#include <VBox/com/com.h>
25#include <VBox/com/string.h>
26#include <VBox/com/Guid.h>
27#include <VBox/com/array.h>
28#include <VBox/com/ErrorInfo.h>
29#include <VBox/com/errorprint.h>
30
31#include <VBox/com/VirtualBox.h>
32
33#include <VBox/log.h>
34#include <iprt/stream.h>
35#include <iprt/string.h>
36#include <iprt/time.h>
37#include <iprt/getopt.h>
38#include <iprt/ctype.h>
39
40#include <vector>
41#include <algorithm>
42
43#include "VBoxManage.h"
44using namespace com;
45
46#ifdef VBOX_WITH_HOSTNETIF_API
47static const char *getHostIfMediumTypeText(HostNetworkInterfaceMediumType_T enmType)
48{
49 switch (enmType)
50 {
51 case HostNetworkInterfaceMediumType_Ethernet: return "Ethernet";
52 case HostNetworkInterfaceMediumType_PPP: return "PPP";
53 case HostNetworkInterfaceMediumType_SLIP: return "SLIP";
54 case HostNetworkInterfaceMediumType_Unknown: return "Unknown";
55#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
56 case HostNetworkInterfaceMediumType_32BitHack: break; /* Shut up compiler warnings. */
57#endif
58 }
59 return "unknown";
60}
61
62static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
63{
64 switch (enmStatus)
65 {
66 case HostNetworkInterfaceStatus_Up: return "Up";
67 case HostNetworkInterfaceStatus_Down: return "Down";
68 case HostNetworkInterfaceStatus_Unknown: return "Unknown";
69#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
70 case HostNetworkInterfaceStatus_32BitHack: break; /* Shut up compiler warnings. */
71#endif
72 }
73 return "unknown";
74}
75#endif /* VBOX_WITH_HOSTNETIF_API */
76
77static const char*getDeviceTypeText(DeviceType_T enmType)
78{
79 switch (enmType)
80 {
81 case DeviceType_HardDisk: return "HardDisk";
82 case DeviceType_DVD: return "DVD";
83 case DeviceType_Floppy: return "Floppy";
84 /* Make MSC happy */
85 case DeviceType_Null: return "Null";
86 case DeviceType_Network: return "Network";
87 case DeviceType_USB: return "USB";
88 case DeviceType_SharedFolder: return "SharedFolder";
89 case DeviceType_Graphics3D: return "Graphics3D";
90#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
91 case DeviceType_32BitHack: break; /* Shut up compiler warnings. */
92#endif
93 }
94 return "Unknown";
95}
96
97
98/**
99 * List internal networks.
100 *
101 * @returns See produceList.
102 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
103 */
104static HRESULT listInternalNetworks(const ComPtr<IVirtualBox> pVirtualBox)
105{
106 HRESULT rc;
107 com::SafeArray<BSTR> internalNetworks;
108 CHECK_ERROR(pVirtualBox, COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks)));
109 for (size_t i = 0; i < internalNetworks.size(); ++i)
110 {
111 RTPrintf("Name: %ls\n", internalNetworks[i]);
112 }
113 return rc;
114}
115
116
117/**
118 * List network interfaces information (bridged/host only).
119 *
120 * @returns See produceList.
121 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
122 * @param fIsBridged Selects between listing host interfaces (for
123 * use with bridging) or host only interfaces.
124 */
125static HRESULT listNetworkInterfaces(const ComPtr<IVirtualBox> pVirtualBox,
126 bool fIsBridged)
127{
128 HRESULT rc;
129 ComPtr<IHost> host;
130 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
131 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
132#if defined(VBOX_WITH_NETFLT)
133 if (fIsBridged)
134 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
135 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
136 else
137 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
138 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
139#else
140 RT_NOREF(fIsBridged);
141 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
142#endif
143 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
144 {
145 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
146#ifndef VBOX_WITH_HOSTNETIF_API
147 Bstr interfaceName;
148 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
149 RTPrintf("Name: %ls\n", interfaceName.raw());
150 Guid interfaceGuid;
151 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
152 RTPrintf("GUID: %ls\n\n", Bstr(interfaceGuid.toString()).raw());
153#else /* VBOX_WITH_HOSTNETIF_API */
154 Bstr interfaceName;
155 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
156 RTPrintf("Name: %ls\n", interfaceName.raw());
157 Bstr interfaceGuid;
158 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
159 RTPrintf("GUID: %ls\n", interfaceGuid.raw());
160 BOOL fDHCPEnabled = FALSE;
161 networkInterface->COMGETTER(DHCPEnabled)(&fDHCPEnabled);
162 RTPrintf("DHCP: %s\n", fDHCPEnabled ? "Enabled" : "Disabled");
163
164 Bstr IPAddress;
165 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
166 RTPrintf("IPAddress: %ls\n", IPAddress.raw());
167 Bstr NetworkMask;
168 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
169 RTPrintf("NetworkMask: %ls\n", NetworkMask.raw());
170 Bstr IPV6Address;
171 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
172 RTPrintf("IPV6Address: %ls\n", IPV6Address.raw());
173 ULONG IPV6NetworkMaskPrefixLength;
174 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
175 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
176 Bstr HardwareAddress;
177 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
178 RTPrintf("HardwareAddress: %ls\n", HardwareAddress.raw());
179 HostNetworkInterfaceMediumType_T Type;
180 networkInterface->COMGETTER(MediumType)(&Type);
181 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
182 BOOL fWireless = FALSE;
183 networkInterface->COMGETTER(Wireless)(&fWireless);
184 RTPrintf("Wireless: %s\n", fWireless ? "Yes" : "No");
185 HostNetworkInterfaceStatus_T Status;
186 networkInterface->COMGETTER(Status)(&Status);
187 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
188 Bstr netName;
189 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
190 RTPrintf("VBoxNetworkName: %ls\n\n", netName.raw());
191#endif
192 }
193 return rc;
194}
195
196
197#ifdef VBOX_WITH_CLOUD_NET
198/**
199 * List configured cloud network attachments.
200 *
201 * @returns See produceList.
202 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
203 * @param Reserved Placeholder!
204 */
205static HRESULT listCloudNetworks(const ComPtr<IVirtualBox> pVirtualBox)
206{
207 HRESULT rc;
208 com::SafeIfaceArray<ICloudNetwork> cloudNetworks;
209 CHECK_ERROR(pVirtualBox, COMGETTER(CloudNetworks)(ComSafeArrayAsOutParam(cloudNetworks)));
210 for (size_t i = 0; i < cloudNetworks.size(); ++i)
211 {
212 ComPtr<ICloudNetwork> cloudNetwork = cloudNetworks[i];
213 Bstr networkName;
214 cloudNetwork->COMGETTER(NetworkName)(networkName.asOutParam());
215 RTPrintf("Name: %ls\n", networkName.raw());
216 // Guid interfaceGuid;
217 // cloudNetwork->COMGETTER(Id)(interfaceGuid.asOutParam());
218 // RTPrintf("GUID: %ls\n\n", Bstr(interfaceGuid.toString()).raw());
219 BOOL fEnabled = FALSE;
220 cloudNetwork->COMGETTER(Enabled)(&fEnabled);
221 RTPrintf("State: %s\n", fEnabled ? "Enabled" : "Disabled");
222
223 Bstr Provider;
224 cloudNetwork->COMGETTER(Provider)(Provider.asOutParam());
225 RTPrintf("CloudProvider: %ls\n", Provider.raw());
226 Bstr Profile;
227 cloudNetwork->COMGETTER(Profile)(Profile.asOutParam());
228 RTPrintf("CloudProfile: %ls\n", Profile.raw());
229 Bstr NetworkId;
230 cloudNetwork->COMGETTER(NetworkId)(NetworkId.asOutParam());
231 RTPrintf("CloudNetworkId: %ls\n", NetworkId.raw());
232 Bstr netName = BstrFmt("cloud-%ls", networkName.raw());
233 RTPrintf("VBoxNetworkName: %ls\n\n", netName.raw());
234 }
235 return rc;
236}
237#endif /* VBOX_WITH_CLOUD_NET */
238
239
240/**
241 * List host information.
242 *
243 * @returns See produceList.
244 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
245 */
246static HRESULT listHostInfo(const ComPtr<IVirtualBox> pVirtualBox)
247{
248 static struct
249 {
250 ProcessorFeature_T feature;
251 const char *pszName;
252 } features[]
253 =
254 {
255 { ProcessorFeature_HWVirtEx, "HW virtualization" },
256 { ProcessorFeature_PAE, "PAE" },
257 { ProcessorFeature_LongMode, "long mode" },
258 { ProcessorFeature_NestedPaging, "nested paging" },
259 { ProcessorFeature_UnrestrictedGuest, "unrestricted guest" },
260 { ProcessorFeature_NestedHWVirt, "nested HW virtualization" },
261 };
262 HRESULT rc;
263 ComPtr<IHost> Host;
264 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
265
266 RTPrintf("Host Information:\n\n");
267
268 LONG64 u64UtcTime = 0;
269 CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
270 RTTIMESPEC timeSpec;
271 char szTime[32];
272 RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
273
274 ULONG processorOnlineCount = 0;
275 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
276 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
277 ULONG processorCount = 0;
278 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
279 RTPrintf("Processor count: %lu\n", processorCount);
280 ULONG processorOnlineCoreCount = 0;
281 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCoreCount)(&processorOnlineCoreCount));
282 RTPrintf("Processor online core count: %lu\n", processorOnlineCoreCount);
283 ULONG processorCoreCount = 0;
284 CHECK_ERROR(Host, COMGETTER(ProcessorCoreCount)(&processorCoreCount));
285 RTPrintf("Processor core count: %lu\n", processorCoreCount);
286 for (unsigned i = 0; i < RT_ELEMENTS(features); i++)
287 {
288 BOOL supported;
289 CHECK_ERROR(Host, GetProcessorFeature(features[i].feature, &supported));
290 RTPrintf("Processor supports %s: %s\n", features[i].pszName, supported ? "yes" : "no");
291 }
292 for (ULONG i = 0; i < processorCount; i++)
293 {
294 ULONG processorSpeed = 0;
295 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
296 if (processorSpeed)
297 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
298 else
299 RTPrintf("Processor#%u speed: unknown\n", i);
300 Bstr processorDescription;
301 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
302 RTPrintf("Processor#%u description: %ls\n", i, processorDescription.raw());
303 }
304
305 ULONG memorySize = 0;
306 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
307 RTPrintf("Memory size: %lu MByte\n", memorySize);
308
309 ULONG memoryAvailable = 0;
310 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
311 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
312
313 Bstr operatingSystem;
314 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
315 RTPrintf("Operating system: %ls\n", operatingSystem.raw());
316
317 Bstr oSVersion;
318 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
319 RTPrintf("Operating system version: %ls\n", oSVersion.raw());
320 return rc;
321}
322
323
324/**
325 * List media information.
326 *
327 * @returns See produceList.
328 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
329 * @param aMedia Medium objects to list information for.
330 * @param pszParentUUIDStr String with the parent UUID string (or "base").
331 * @param fOptLong Long (@c true) or short list format.
332 */
333static HRESULT listMedia(const ComPtr<IVirtualBox> pVirtualBox,
334 const com::SafeIfaceArray<IMedium> &aMedia,
335 const char *pszParentUUIDStr,
336 bool fOptLong)
337{
338 HRESULT rc = S_OK;
339 for (size_t i = 0; i < aMedia.size(); ++i)
340 {
341 ComPtr<IMedium> pMedium = aMedia[i];
342
343 rc = showMediumInfo(pVirtualBox, pMedium, pszParentUUIDStr, fOptLong);
344
345 RTPrintf("\n");
346
347 com::SafeIfaceArray<IMedium> children;
348 CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
349 if (children.size() > 0)
350 {
351 Bstr uuid;
352 pMedium->COMGETTER(Id)(uuid.asOutParam());
353
354 // depth first listing of child media
355 rc = listMedia(pVirtualBox, children, Utf8Str(uuid).c_str(), fOptLong);
356 }
357 }
358
359 return rc;
360}
361
362
363/**
364 * List virtual image backends.
365 *
366 * @returns See produceList.
367 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
368 */
369static HRESULT listHddBackends(const ComPtr<IVirtualBox> pVirtualBox)
370{
371 HRESULT rc;
372 ComPtr<ISystemProperties> systemProperties;
373 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
374 com::SafeIfaceArray<IMediumFormat> mediumFormats;
375 CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
376
377 RTPrintf("Supported hard disk backends:\n\n");
378 for (size_t i = 0; i < mediumFormats.size(); ++i)
379 {
380 /* General information */
381 Bstr id;
382 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
383
384 Bstr description;
385 CHECK_ERROR(mediumFormats[i],
386 COMGETTER(Name)(description.asOutParam()));
387
388 ULONG caps = 0;
389 com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap;
390 CHECK_ERROR(mediumFormats[i],
391 COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap)));
392 for (ULONG j = 0; j < mediumFormatCap.size(); j++)
393 caps |= mediumFormatCap[j];
394
395
396 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
397 i, id.raw(), description.raw(), caps);
398
399 /* File extensions */
400 com::SafeArray<BSTR> fileExtensions;
401 com::SafeArray<DeviceType_T> deviceTypes;
402 CHECK_ERROR(mediumFormats[i],
403 DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
404 for (size_t j = 0; j < fileExtensions.size(); ++j)
405 {
406 RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
407 if (j != fileExtensions.size()-1)
408 RTPrintf(",");
409 }
410 RTPrintf("'");
411
412 /* Configuration keys */
413 com::SafeArray<BSTR> propertyNames;
414 com::SafeArray<BSTR> propertyDescriptions;
415 com::SafeArray<DataType_T> propertyTypes;
416 com::SafeArray<ULONG> propertyFlags;
417 com::SafeArray<BSTR> propertyDefaults;
418 CHECK_ERROR(mediumFormats[i],
419 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
420 ComSafeArrayAsOutParam(propertyDescriptions),
421 ComSafeArrayAsOutParam(propertyTypes),
422 ComSafeArrayAsOutParam(propertyFlags),
423 ComSafeArrayAsOutParam(propertyDefaults)));
424
425 RTPrintf(" properties=(");
426 if (propertyNames.size() > 0)
427 {
428 for (size_t j = 0; j < propertyNames.size(); ++j)
429 {
430 RTPrintf("\n name='%ls' desc='%ls' type=",
431 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
432 switch (propertyTypes[j])
433 {
434 case DataType_Int32: RTPrintf("int"); break;
435 case DataType_Int8: RTPrintf("byte"); break;
436 case DataType_String: RTPrintf("string"); break;
437#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
438 case DataType_32BitHack: break; /* Shut up compiler warnings. */
439#endif
440 }
441 RTPrintf(" flags=%#04x", propertyFlags[j]);
442 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
443 if (j != propertyNames.size()-1)
444 RTPrintf(", ");
445 }
446 }
447 RTPrintf(")\n");
448 }
449 return rc;
450}
451
452
453/**
454 * List USB devices attached to the host.
455 *
456 * @returns See produceList.
457 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
458 */
459static HRESULT listUsbHost(const ComPtr<IVirtualBox> &pVirtualBox)
460{
461 HRESULT rc;
462 ComPtr<IHost> Host;
463 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
464
465 SafeIfaceArray<IHostUSBDevice> CollPtr;
466 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
467
468 RTPrintf("Host USB Devices:\n\n");
469
470 if (CollPtr.size() == 0)
471 {
472 RTPrintf("<none>\n\n");
473 }
474 else
475 {
476 for (size_t i = 0; i < CollPtr.size(); ++i)
477 {
478 ComPtr<IHostUSBDevice> dev = CollPtr[i];
479
480 /* Query info. */
481 Bstr id;
482 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
483 USHORT usVendorId;
484 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
485 USHORT usProductId;
486 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
487 USHORT bcdRevision;
488 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
489 USHORT usPort;
490 CHECK_ERROR_RET(dev, COMGETTER(Port)(&usPort), 1);
491 USHORT usVersion;
492 CHECK_ERROR_RET(dev, COMGETTER(Version)(&usVersion), 1);
493 USBConnectionSpeed_T enmSpeed;
494 CHECK_ERROR_RET(dev, COMGETTER(Speed)(&enmSpeed), 1);
495
496 RTPrintf("UUID: %s\n"
497 "VendorId: %#06x (%04X)\n"
498 "ProductId: %#06x (%04X)\n"
499 "Revision: %u.%u (%02u%02u)\n"
500 "Port: %u\n",
501 Utf8Str(id).c_str(),
502 usVendorId, usVendorId, usProductId, usProductId,
503 bcdRevision >> 8, bcdRevision & 0xff,
504 bcdRevision >> 8, bcdRevision & 0xff,
505 usPort);
506
507 const char *pszSpeed = "?";
508 switch (enmSpeed)
509 {
510 case USBConnectionSpeed_Low:
511 pszSpeed = "Low";
512 break;
513 case USBConnectionSpeed_Full:
514 pszSpeed = "Full";
515 break;
516 case USBConnectionSpeed_High:
517 pszSpeed = "High";
518 break;
519 case USBConnectionSpeed_Super:
520 pszSpeed = "Super";
521 break;
522 case USBConnectionSpeed_SuperPlus:
523 pszSpeed = "SuperPlus";
524 break;
525 default:
526 ASSERT(false);
527 break;
528 }
529
530 RTPrintf("USB version/speed: %u/%s\n", usVersion, pszSpeed);
531
532 /* optional stuff. */
533 SafeArray<BSTR> CollDevInfo;
534 Bstr bstr;
535 CHECK_ERROR_RET(dev, COMGETTER(DeviceInfo)(ComSafeArrayAsOutParam(CollDevInfo)), 1);
536 if (CollDevInfo.size() >= 1)
537 bstr = Bstr(CollDevInfo[0]);
538 if (!bstr.isEmpty())
539 RTPrintf("Manufacturer: %ls\n", bstr.raw());
540 if (CollDevInfo.size() >= 2)
541 bstr = Bstr(CollDevInfo[1]);
542 if (!bstr.isEmpty())
543 RTPrintf("Product: %ls\n", bstr.raw());
544 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
545 if (!bstr.isEmpty())
546 RTPrintf("SerialNumber: %ls\n", bstr.raw());
547 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
548 if (!bstr.isEmpty())
549 RTPrintf("Address: %ls\n", bstr.raw());
550 CHECK_ERROR_RET(dev, COMGETTER(PortPath)(bstr.asOutParam()), 1);
551 if (!bstr.isEmpty())
552 RTPrintf("Port path: %ls\n", bstr.raw());
553
554 /* current state */
555 USBDeviceState_T state;
556 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
557 const char *pszState = "?";
558 switch (state)
559 {
560 case USBDeviceState_NotSupported:
561 pszState = "Not supported";
562 break;
563 case USBDeviceState_Unavailable:
564 pszState = "Unavailable";
565 break;
566 case USBDeviceState_Busy:
567 pszState = "Busy";
568 break;
569 case USBDeviceState_Available:
570 pszState = "Available";
571 break;
572 case USBDeviceState_Held:
573 pszState = "Held";
574 break;
575 case USBDeviceState_Captured:
576 pszState = "Captured";
577 break;
578 default:
579 ASSERT(false);
580 break;
581 }
582 RTPrintf("Current State: %s\n\n", pszState);
583 }
584 }
585 return rc;
586}
587
588
589/**
590 * List USB filters.
591 *
592 * @returns See produceList.
593 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
594 */
595static HRESULT listUsbFilters(const ComPtr<IVirtualBox> &pVirtualBox)
596{
597 HRESULT rc;
598
599 RTPrintf("Global USB Device Filters:\n\n");
600
601 ComPtr<IHost> host;
602 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
603
604 SafeIfaceArray<IHostUSBDeviceFilter> coll;
605 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
606
607 if (coll.size() == 0)
608 {
609 RTPrintf("<none>\n\n");
610 }
611 else
612 {
613 for (size_t index = 0; index < coll.size(); ++index)
614 {
615 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
616
617 /* Query info. */
618
619 RTPrintf("Index: %zu\n", index);
620
621 BOOL active = FALSE;
622 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
623 RTPrintf("Active: %s\n", active ? "yes" : "no");
624
625 USBDeviceFilterAction_T action;
626 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
627 const char *pszAction = "<invalid>";
628 switch (action)
629 {
630 case USBDeviceFilterAction_Ignore:
631 pszAction = "Ignore";
632 break;
633 case USBDeviceFilterAction_Hold:
634 pszAction = "Hold";
635 break;
636 default:
637 break;
638 }
639 RTPrintf("Action: %s\n", pszAction);
640
641 Bstr bstr;
642 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
643 RTPrintf("Name: %ls\n", bstr.raw());
644 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
645 RTPrintf("VendorId: %ls\n", bstr.raw());
646 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
647 RTPrintf("ProductId: %ls\n", bstr.raw());
648 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
649 RTPrintf("Revision: %ls\n", bstr.raw());
650 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
651 RTPrintf("Manufacturer: %ls\n", bstr.raw());
652 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
653 RTPrintf("Product: %ls\n", bstr.raw());
654 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
655 RTPrintf("Serial Number: %ls\n\n", bstr.raw());
656 }
657 }
658 return rc;
659}
660
661
662/**
663 * List system properties.
664 *
665 * @returns See produceList.
666 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
667 */
668static HRESULT listSystemProperties(const ComPtr<IVirtualBox> &pVirtualBox)
669{
670 ComPtr<ISystemProperties> systemProperties;
671 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()), hrcCheck);
672
673 Bstr str;
674 ULONG ulValue;
675 LONG64 i64Value;
676 BOOL fValue;
677 const char *psz;
678
679 pVirtualBox->COMGETTER(APIVersion)(str.asOutParam());
680 RTPrintf("API version: %ls\n", str.raw());
681
682 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
683 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
684 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
685 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
686 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
687 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
688 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
689 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
690 systemProperties->COMGETTER(MaxGuestMonitors)(&ulValue);
691 RTPrintf("Maximum guest monitor count: %u\n", ulValue);
692 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
693 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
694 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
695 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
696 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
697 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
698 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
699 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
700 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
701 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
702 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
703 RTPrintf("Maximum Boot Position: %u\n", ulValue);
704 systemProperties->GetMaxNetworkAdapters(ChipsetType_PIIX3, &ulValue);
705 RTPrintf("Maximum PIIX3 Network Adapter count: %u\n", ulValue);
706 systemProperties->GetMaxNetworkAdapters(ChipsetType_ICH9, &ulValue);
707 RTPrintf("Maximum ICH9 Network Adapter count: %u\n", ulValue);
708 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
709 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
710 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
711 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
712 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
713 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
714 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
715 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
716 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
717 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
718 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
719 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
720 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
721 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
722 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
723 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
724 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
725 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
726 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
727 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
728 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
729 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
730 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
731 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
732 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
733 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
734 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
735 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
736 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
737 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
738 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
739 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
740 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_PCIe, &ulValue);
741 RTPrintf("Maximum NVMe PIIX3 Controllers: %u\n", ulValue);
742 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_PCIe, &ulValue);
743 RTPrintf("Maximum NVMe ICH9 Controllers: %u\n", ulValue);
744 systemProperties->GetMaxPortCountForStorageBus(StorageBus_PCIe, &ulValue);
745 RTPrintf("Maximum NVMe Port count: %u\n", ulValue);
746 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_PCIe, &ulValue);
747 RTPrintf("Maximum Devices per NVMe Port: %u\n", ulValue);
748 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_VirtioSCSI, &ulValue);
749 RTPrintf("Maximum virtio-scsi PIIX3 Controllers: %u\n", ulValue);
750 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_VirtioSCSI, &ulValue);
751 RTPrintf("Maximum virtio-scsi ICH9 Controllers: %u\n", ulValue);
752 systemProperties->GetMaxPortCountForStorageBus(StorageBus_VirtioSCSI, &ulValue);
753 RTPrintf("Maximum virtio-scsi Port count: %u\n", ulValue);
754 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_VirtioSCSI, &ulValue);
755 RTPrintf("Maximum Devices per virtio-scsi Port: %u\n", ulValue);
756 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
757 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
758 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
759 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
760 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
761 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
762 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
763 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
764#if 0
765 systemProperties->GetFreeDiskSpaceWarning(&i64Value);
766 RTPrintf("Free disk space warning at: %u Bytes\n", i64Value);
767 systemProperties->GetFreeDiskSpacePercentWarning(&ulValue);
768 RTPrintf("Free disk space warning at: %u %%\n", ulValue);
769 systemProperties->GetFreeDiskSpaceError(&i64Value);
770 RTPrintf("Free disk space error at: %u Bytes\n", i64Value);
771 systemProperties->GetFreeDiskSpacePercentError(&ulValue);
772 RTPrintf("Free disk space error at: %u %%\n", ulValue);
773#endif
774 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
775 RTPrintf("Default machine folder: %ls\n", str.raw());
776 systemProperties->COMGETTER(RawModeSupported)(&fValue);
777 RTPrintf("Raw-mode Supported: %s\n", fValue ? "yes" : "no");
778 systemProperties->COMGETTER(ExclusiveHwVirt)(&fValue);
779 RTPrintf("Exclusive HW virtualization use: %s\n", fValue ? "on" : "off");
780 systemProperties->COMGETTER(DefaultHardDiskFormat)(str.asOutParam());
781 RTPrintf("Default hard disk format: %ls\n", str.raw());
782 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
783 RTPrintf("VRDE auth library: %ls\n", str.raw());
784 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
785 RTPrintf("Webservice auth. library: %ls\n", str.raw());
786 systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
787 RTPrintf("Remote desktop ExtPack: %ls\n", str.raw());
788 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
789 RTPrintf("Log history count: %u\n", ulValue);
790 systemProperties->COMGETTER(DefaultFrontend)(str.asOutParam());
791 RTPrintf("Default frontend: %ls\n", str.raw());
792 AudioDriverType_T enmAudio;
793 systemProperties->COMGETTER(DefaultAudioDriver)(&enmAudio);
794 switch (enmAudio)
795 {
796 case AudioDriverType_Null: psz = "Null"; break;
797 case AudioDriverType_WinMM: psz = "WinMM"; break;
798 case AudioDriverType_OSS: psz = "OSS"; break;
799 case AudioDriverType_ALSA: psz = "ALSA"; break;
800 case AudioDriverType_DirectSound: psz = "DirectSound"; break;
801 case AudioDriverType_CoreAudio: psz = "CoreAudio"; break;
802 case AudioDriverType_MMPM: psz = "MMPM"; break;
803 case AudioDriverType_Pulse: psz = "Pulse"; break;
804 case AudioDriverType_SolAudio: psz = "SolAudio"; break;
805 default: psz = "Unknown";
806 }
807 RTPrintf("Default audio driver: %s\n", psz);
808 systemProperties->COMGETTER(AutostartDatabasePath)(str.asOutParam());
809 RTPrintf("Autostart database path: %ls\n", str.raw());
810 systemProperties->COMGETTER(DefaultAdditionsISO)(str.asOutParam());
811 RTPrintf("Default Guest Additions ISO: %ls\n", str.raw());
812 systemProperties->COMGETTER(LoggingLevel)(str.asOutParam());
813 RTPrintf("Logging Level: %ls\n", str.raw());
814 ProxyMode_T enmProxyMode = (ProxyMode_T)42;
815 systemProperties->COMGETTER(ProxyMode)(&enmProxyMode);
816 psz = "Unknown";
817 switch (enmProxyMode)
818 {
819 case ProxyMode_System: psz = "System"; break;
820 case ProxyMode_NoProxy: psz = "NoProxy"; break;
821 case ProxyMode_Manual: psz = "Manual"; break;
822#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
823 case ProxyMode_32BitHack: break; /* Shut up compiler warnings. */
824#endif
825 }
826 RTPrintf("Proxy Mode: %s\n", psz);
827 systemProperties->COMGETTER(ProxyURL)(str.asOutParam());
828 RTPrintf("Proxy URL: %ls\n", str.raw());
829 return S_OK;
830}
831
832
833/**
834 * Helper for listDhcpServers() that shows a DHCP configuration.
835 */
836static HRESULT showDhcpConfig(ComPtr<IDHCPConfig> ptrConfig)
837{
838 HRESULT hrcRet = S_OK;
839
840 ULONG secs = 0;
841 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MinLeaseTime)(&secs), hrcRet = hrcCheck);
842 if (secs == 0)
843 RTPrintf(" minLeaseTime: default\n");
844 else
845 RTPrintf(" minLeaseTime: %u sec\n", secs);
846
847 secs = 0;
848 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(DefaultLeaseTime)(&secs), hrcRet = hrcCheck);
849 if (secs == 0)
850 RTPrintf(" defaultLeaseTime: default\n");
851 else
852 RTPrintf(" defaultLeaseTime: %u sec\n", secs);
853
854 secs = 0;
855 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MaxLeaseTime)(&secs), hrcRet = hrcCheck);
856 if (secs == 0)
857 RTPrintf(" maxLeaseTime: default\n");
858 else
859 RTPrintf(" maxLeaseTime: %u sec\n", secs);
860
861 com::SafeArray<DHCPOption_T> Options;
862 HRESULT hrc;
863 CHECK_ERROR2_STMT(hrc, ptrConfig, COMGETTER(ForcedOptions(ComSafeArrayAsOutParam(Options))), hrcRet = hrc);
864 if (FAILED(hrc))
865 RTPrintf(" Forced options: %Rhrc\n", hrc);
866 else if (Options.size() == 0)
867 RTPrintf(" Forced options: None\n");
868 else
869 {
870 RTPrintf(" Forced options: ");
871 for (size_t i = 0; i < Options.size(); i++)
872 RTPrintf(i ? ", %u" : "%u", Options[i]);
873 RTPrintf("\n");
874 }
875
876 CHECK_ERROR2_STMT(hrc, ptrConfig, COMGETTER(SuppressedOptions(ComSafeArrayAsOutParam(Options))), hrcRet = hrc);
877 if (FAILED(hrc))
878 RTPrintf(" Suppressed opt.s: %Rhrc\n", hrc);
879 else if (Options.size() == 0)
880 RTPrintf(" Suppressed opts.: None\n");
881 else
882 {
883 RTPrintf(" Suppressed opts.: ");
884 for (size_t i = 0; i < Options.size(); i++)
885 RTPrintf(i ? ", %u" : "%u", Options[i]);
886 RTPrintf("\n");
887 }
888
889 com::SafeArray<DHCPOptionEncoding_T> Encodings;
890 com::SafeArray<BSTR> Values;
891 CHECK_ERROR2_STMT(hrc, ptrConfig, GetAllOptions(ComSafeArrayAsOutParam(Options),
892 ComSafeArrayAsOutParam(Encodings),
893 ComSafeArrayAsOutParam(Values)), hrcRet = hrc);
894 if (FAILED(hrc))
895 RTPrintf(" DHCP options: %Rhrc\n", hrc);
896 else if (Options.size() != Encodings.size() || Options.size() != Values.size())
897 {
898 RTPrintf(" DHCP options: Return count mismatch: %zu, %zu, %zu\n", Options.size(), Encodings.size(), Values.size());
899 hrcRet = E_FAIL;
900 }
901 else if (Options.size() == 0)
902 RTPrintf(" DHCP options: None\n");
903 else
904 for (size_t i = 0; i < Options.size(); i++)
905 {
906 switch (Encodings[i])
907 {
908 case DHCPOptionEncoding_Normal:
909 RTPrintf(" %3d/legacy: %ls\n", Options[i], Values[i]);
910 break;
911 case DHCPOptionEncoding_Hex:
912 RTPrintf(" %3d/hex: %ls\n", Options[i], Values[i]);
913 break;
914 default:
915 RTPrintf(" %3d/%u?: %ls\n", Options[i], Encodings[i], Values[i]);
916 break;
917 }
918 }
919
920 return S_OK;
921}
922
923
924/**
925 * List DHCP servers.
926 *
927 * @returns See produceList.
928 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
929 */
930static HRESULT listDhcpServers(const ComPtr<IVirtualBox> &pVirtualBox)
931{
932 HRESULT hrcRet = S_OK;
933 com::SafeIfaceArray<IDHCPServer> DHCPServers;
934 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers)), hrcCheck);
935 for (size_t i = 0; i < DHCPServers.size(); ++i)
936 {
937 if (i > 0)
938 RTPrintf("\n");
939
940 ComPtr<IDHCPServer> ptrDHCPServer = DHCPServers[i];
941 Bstr bstr;
942 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(NetworkName)(bstr.asOutParam()), hrcRet = hrcCheck);
943 RTPrintf("NetworkName: %ls\n", bstr.raw());
944
945 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(IPAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
946 RTPrintf("Dhcpd IP: %ls\n", bstr.raw());
947
948 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(LowerIP)(bstr.asOutParam()), hrcRet = hrcCheck);
949 RTPrintf("LowerIPAddress: %ls\n", bstr.raw());
950
951 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(UpperIP)(bstr.asOutParam()), hrcRet = hrcCheck);
952 RTPrintf("UpperIPAddress: %ls\n", bstr.raw());
953
954 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(NetworkMask)(bstr.asOutParam()), hrcRet = hrcCheck);
955 RTPrintf("NetworkMask: %ls\n", bstr.raw());
956
957 BOOL fEnabled = FALSE;
958 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(Enabled)(&fEnabled), hrcRet = hrcCheck);
959 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
960
961 /* Global configuration: */
962 RTPrintf("Global Configuration:\n");
963 HRESULT hrc;
964 ComPtr<IDHCPGlobalConfig> ptrGlobal;
965 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(GlobalConfig)(ptrGlobal.asOutParam()), hrcRet = hrc);
966 if (SUCCEEDED(hrc))
967 {
968 hrc = showDhcpConfig(ptrGlobal);
969 if (FAILED(hrc))
970 hrcRet = hrc;
971 }
972
973 /* Group configurations: */
974 com::SafeIfaceArray<IDHCPGroupConfig> Groups;
975 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(GroupConfigs)(ComSafeArrayAsOutParam(Groups)), hrcRet = hrc);
976 if (FAILED(hrc))
977 RTPrintf("Groups: %Rrc\n", hrc);
978 else if (Groups.size() == 0)
979 RTPrintf("Groups: None\n");
980 else
981 {
982 for (size_t iGrp = 0; iGrp < Groups.size(); iGrp++)
983 {
984 CHECK_ERROR2I_STMT(Groups[iGrp], COMGETTER(Name)(bstr.asOutParam()), hrcRet = hrcCheck);
985 RTPrintf("Group: %ls\n", bstr.raw());
986
987 com::SafeIfaceArray<IDHCPGroupCondition> Conditions;
988 CHECK_ERROR2_STMT(hrc, Groups[iGrp], COMGETTER(Conditions)(ComSafeArrayAsOutParam(Conditions)), hrcRet = hrc);
989 if (FAILED(hrc))
990 RTPrintf(" Conditions: %Rhrc\n", hrc);
991 else if (Conditions.size() == 0)
992 RTPrintf(" Conditions: None\n");
993 else
994 for (size_t iCond = 0; iCond < Conditions.size(); iCond++)
995 {
996 BOOL fInclusive = TRUE;
997 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Inclusive)(&fInclusive), hrcRet = hrc);
998 DHCPGroupConditionType_T enmType = DHCPGroupConditionType_MAC;
999 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Type)(&enmType), hrcRet = hrc);
1000 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Value)(bstr.asOutParam()), hrcRet = hrc);
1001
1002 RTPrintf(" Conditions: %s %s %ls\n",
1003 fInclusive ? "include" : "exclude",
1004 enmType == DHCPGroupConditionType_MAC ? "MAC "
1005 : enmType == DHCPGroupConditionType_MACWildcard ? "MAC* "
1006 : enmType == DHCPGroupConditionType_vendorClassID ? "VendorCID "
1007 : enmType == DHCPGroupConditionType_vendorClassIDWildcard ? "VendorCID*"
1008 : enmType == DHCPGroupConditionType_userClassID ? "UserCID "
1009 : enmType == DHCPGroupConditionType_userClassIDWildcard ? "UserCID* "
1010 : "!UNKNOWN! ",
1011 bstr.raw());
1012 }
1013
1014 hrc = showDhcpConfig(Groups[iGrp]);
1015 if (FAILED(hrc))
1016 hrcRet = hrc;
1017 }
1018 Groups.setNull();
1019 }
1020
1021 /* Individual host / NIC configurations: */
1022 com::SafeIfaceArray<IDHCPIndividualConfig> Hosts;
1023 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(IndividualConfigs)(ComSafeArrayAsOutParam(Hosts)), hrcRet = hrc);
1024 if (FAILED(hrc))
1025 RTPrintf("Individual Configs: %Rrc\n", hrc);
1026 else if (Hosts.size() == 0)
1027 RTPrintf("Individual Configs: None\n");
1028 else
1029 {
1030 for (size_t iHost = 0; iHost < Hosts.size(); iHost++)
1031 {
1032 DHCPConfigScope_T enmScope = DHCPConfigScope_MAC;
1033 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Scope)(&enmScope), hrcRet = hrcCheck);
1034
1035 if (enmScope == DHCPConfigScope_MAC)
1036 {
1037 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(MACAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
1038 RTPrintf("Individual Config: MAC %ls\n", bstr.raw());
1039 }
1040 else
1041 {
1042 ULONG uSlot = 0;
1043 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Slot)(&uSlot), hrcRet = hrcCheck);
1044 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(MachineId)(bstr.asOutParam()), hrcRet = hrcCheck);
1045 Bstr bstrMACAddress;
1046 hrc = Hosts[iHost]->COMGETTER(MACAddress)(bstrMACAddress.asOutParam()); /* No CHECK_ERROR2 stuff! */
1047 if (SUCCEEDED(hrc))
1048 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %ls\n", bstr.raw(), uSlot, bstrMACAddress.raw());
1049 else
1050 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %Rhrc\n", bstr.raw(), uSlot, hrc);
1051 }
1052
1053 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(FixedAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
1054 if (bstr.isNotEmpty())
1055 RTPrintf(" Fixed Address: %ls\n", bstr.raw());
1056 else
1057 RTPrintf(" Fixed Address: dynamic\n");
1058
1059 hrc = showDhcpConfig(Hosts[iHost]);
1060 if (FAILED(hrc))
1061 hrcRet = hrc;
1062 }
1063 Hosts.setNull();
1064 }
1065 }
1066
1067 return hrcRet;
1068}
1069
1070/**
1071 * List extension packs.
1072 *
1073 * @returns See produceList.
1074 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1075 */
1076static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
1077{
1078 ComObjPtr<IExtPackManager> ptrExtPackMgr;
1079 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
1080
1081 SafeIfaceArray<IExtPack> extPacks;
1082 CHECK_ERROR2I_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
1083 RTPrintf("Extension Packs: %u\n", extPacks.size());
1084
1085 HRESULT hrc = S_OK;
1086 for (size_t i = 0; i < extPacks.size(); i++)
1087 {
1088 /* Read all the properties. */
1089 Bstr bstrName;
1090 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
1091 Bstr bstrDesc;
1092 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
1093 Bstr bstrVersion;
1094 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
1095 ULONG uRevision;
1096 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
1097 Bstr bstrEdition;
1098 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
1099 Bstr bstrVrdeModule;
1100 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
1101 BOOL fUsable;
1102 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
1103 Bstr bstrWhy;
1104 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
1105
1106 /* Display them. */
1107 if (i)
1108 RTPrintf("\n");
1109 RTPrintf("Pack no.%2zu: %ls\n"
1110 "Version: %ls\n"
1111 "Revision: %u\n"
1112 "Edition: %ls\n"
1113 "Description: %ls\n"
1114 "VRDE Module: %ls\n"
1115 "Usable: %RTbool\n"
1116 "Why unusable: %ls\n",
1117 i, bstrName.raw(),
1118 bstrVersion.raw(),
1119 uRevision,
1120 bstrEdition.raw(),
1121 bstrDesc.raw(),
1122 bstrVrdeModule.raw(),
1123 fUsable != FALSE,
1124 bstrWhy.raw());
1125
1126 /* Query plugins and display them. */
1127 }
1128 return hrc;
1129}
1130
1131
1132/**
1133 * List machine groups.
1134 *
1135 * @returns See produceList.
1136 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1137 */
1138static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
1139{
1140 SafeArray<BSTR> groups;
1141 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
1142
1143 for (size_t i = 0; i < groups.size(); i++)
1144 {
1145 RTPrintf("\"%ls\"\n", groups[i]);
1146 }
1147 return S_OK;
1148}
1149
1150
1151/**
1152 * List video capture devices.
1153 *
1154 * @returns See produceList.
1155 * @param pVirtualBox Reference to the IVirtualBox pointer.
1156 */
1157static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> pVirtualBox)
1158{
1159 HRESULT rc;
1160 ComPtr<IHost> host;
1161 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1162 com::SafeIfaceArray<IHostVideoInputDevice> hostVideoInputDevices;
1163 CHECK_ERROR(host, COMGETTER(VideoInputDevices)(ComSafeArrayAsOutParam(hostVideoInputDevices)));
1164 RTPrintf("Video Input Devices: %u\n", hostVideoInputDevices.size());
1165 for (size_t i = 0; i < hostVideoInputDevices.size(); ++i)
1166 {
1167 ComPtr<IHostVideoInputDevice> p = hostVideoInputDevices[i];
1168 Bstr name;
1169 p->COMGETTER(Name)(name.asOutParam());
1170 Bstr path;
1171 p->COMGETTER(Path)(path.asOutParam());
1172 Bstr alias;
1173 p->COMGETTER(Alias)(alias.asOutParam());
1174 RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
1175 }
1176 return rc;
1177}
1178
1179/**
1180 * List supported screen shot formats.
1181 *
1182 * @returns See produceList.
1183 * @param pVirtualBox Reference to the IVirtualBox pointer.
1184 */
1185static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> pVirtualBox)
1186{
1187 HRESULT rc = S_OK;
1188 ComPtr<ISystemProperties> systemProperties;
1189 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
1190 com::SafeArray<BitmapFormat_T> formats;
1191 CHECK_ERROR(systemProperties, COMGETTER(ScreenShotFormats)(ComSafeArrayAsOutParam(formats)));
1192
1193 RTPrintf("Supported %d screen shot formats:\n", formats.size());
1194 for (size_t i = 0; i < formats.size(); ++i)
1195 {
1196 uint32_t u32Format = (uint32_t)formats[i];
1197 char szFormat[5];
1198 szFormat[0] = RT_BYTE1(u32Format);
1199 szFormat[1] = RT_BYTE2(u32Format);
1200 szFormat[2] = RT_BYTE3(u32Format);
1201 szFormat[3] = RT_BYTE4(u32Format);
1202 szFormat[4] = 0;
1203 RTPrintf(" BitmapFormat_%s (0x%08X)\n", szFormat, u32Format);
1204 }
1205 return rc;
1206}
1207
1208/**
1209 * List available cloud providers.
1210 *
1211 * @returns See produceList.
1212 * @param pVirtualBox Reference to the IVirtualBox pointer.
1213 */
1214static HRESULT listCloudProviders(const ComPtr<IVirtualBox> pVirtualBox)
1215{
1216 HRESULT rc = S_OK;
1217 ComPtr<ICloudProviderManager> pCloudProviderManager;
1218 CHECK_ERROR(pVirtualBox, COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()));
1219 com::SafeIfaceArray<ICloudProvider> apCloudProviders;
1220 CHECK_ERROR(pCloudProviderManager, COMGETTER(Providers)(ComSafeArrayAsOutParam(apCloudProviders)));
1221
1222 RTPrintf("Supported %d cloud providers:\n", apCloudProviders.size());
1223 for (size_t i = 0; i < apCloudProviders.size(); ++i)
1224 {
1225 ComPtr<ICloudProvider> pCloudProvider = apCloudProviders[i];
1226 Bstr bstrProviderName;
1227 pCloudProvider->COMGETTER(Name)(bstrProviderName.asOutParam());
1228 RTPrintf("Name: %ls\n", bstrProviderName.raw());
1229 pCloudProvider->COMGETTER(ShortName)(bstrProviderName.asOutParam());
1230 RTPrintf("Short Name: %ls\n", bstrProviderName.raw());
1231 Bstr bstrProviderID;
1232 pCloudProvider->COMGETTER(Id)(bstrProviderID.asOutParam());
1233 RTPrintf("GUID: %ls\n", bstrProviderID.raw());
1234
1235 RTPrintf("\n");
1236 }
1237 return rc;
1238}
1239
1240
1241/**
1242 * List all available cloud profiles (by iterating over the cloud providers).
1243 *
1244 * @returns See produceList.
1245 * @param pVirtualBox Reference to the IVirtualBox pointer.
1246 * @param fOptLong If true, list all profile properties.
1247 */
1248static HRESULT listCloudProfiles(const ComPtr<IVirtualBox> pVirtualBox, bool fOptLong)
1249{
1250 HRESULT rc = S_OK;
1251 ComPtr<ICloudProviderManager> pCloudProviderManager;
1252 CHECK_ERROR(pVirtualBox, COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()));
1253 com::SafeIfaceArray<ICloudProvider> apCloudProviders;
1254 CHECK_ERROR(pCloudProviderManager, COMGETTER(Providers)(ComSafeArrayAsOutParam(apCloudProviders)));
1255
1256 for (size_t i = 0; i < apCloudProviders.size(); ++i)
1257 {
1258 ComPtr<ICloudProvider> pCloudProvider = apCloudProviders[i];
1259 com::SafeIfaceArray<ICloudProfile> apCloudProfiles;
1260 CHECK_ERROR(pCloudProvider, COMGETTER(Profiles)(ComSafeArrayAsOutParam(apCloudProfiles)));
1261 for (size_t j = 0; j < apCloudProfiles.size(); ++j)
1262 {
1263 ComPtr<ICloudProfile> pCloudProfile = apCloudProfiles[j];
1264 Bstr bstrProfileName;
1265 pCloudProfile->COMGETTER(Name)(bstrProfileName.asOutParam());
1266 RTPrintf("Name: %ls\n", bstrProfileName.raw());
1267 Bstr bstrProviderID;
1268 pCloudProfile->COMGETTER(ProviderId)(bstrProviderID.asOutParam());
1269 RTPrintf("Provider GUID: %ls\n", bstrProviderID.raw());
1270
1271 if (fOptLong)
1272 {
1273 com::SafeArray<BSTR> names;
1274 com::SafeArray<BSTR> values;
1275 pCloudProfile->GetProperties(Bstr().raw(), ComSafeArrayAsOutParam(names), ComSafeArrayAsOutParam(values));
1276 size_t cNames = names.size();
1277 size_t cValues = values.size();
1278 bool fFirst = true;
1279 for (size_t k = 0; k < cNames; k++)
1280 {
1281 Bstr value;
1282 if (k < cValues)
1283 value = values[k];
1284 RTPrintf("%s%ls=%ls\n",
1285 fFirst ? "Property: " : " ",
1286 names[k], value.raw());
1287 fFirst = false;
1288 }
1289 }
1290
1291 RTPrintf("\n");
1292 }
1293 }
1294 return rc;
1295}
1296
1297
1298/**
1299 * The type of lists we can produce.
1300 */
1301enum enmListType
1302{
1303 kListNotSpecified = 1000,
1304 kListVMs,
1305 kListRunningVMs,
1306 kListOsTypes,
1307 kListHostDvds,
1308 kListHostFloppies,
1309 kListInternalNetworks,
1310 kListBridgedInterfaces,
1311#if defined(VBOX_WITH_NETFLT)
1312 kListHostOnlyInterfaces,
1313#endif
1314#if defined(VBOX_WITH_CLOUD_NET)
1315 kListCloudNetworks,
1316#endif
1317 kListHostCpuIDs,
1318 kListHostInfo,
1319 kListHddBackends,
1320 kListHdds,
1321 kListDvds,
1322 kListFloppies,
1323 kListUsbHost,
1324 kListUsbFilters,
1325 kListSystemProperties,
1326 kListDhcpServers,
1327 kListExtPacks,
1328 kListGroups,
1329 kListNatNetworks,
1330 kListVideoInputDevices,
1331 kListScreenShotFormats,
1332 kListCloudProviders,
1333 kListCloudProfiles,
1334};
1335
1336
1337/**
1338 * Produces the specified listing.
1339 *
1340 * @returns S_OK or some COM error code that has been reported in full.
1341 * @param enmList The list to produce.
1342 * @param fOptLong Long (@c true) or short list format.
1343 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1344 */
1345static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
1346{
1347 HRESULT rc = S_OK;
1348 switch (enmCommand)
1349 {
1350 case kListNotSpecified:
1351 AssertFailed();
1352 return E_FAIL;
1353
1354 case kListVMs:
1355 {
1356 /*
1357 * Get the list of all registered VMs
1358 */
1359 com::SafeIfaceArray<IMachine> machines;
1360 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1361 if (SUCCEEDED(rc))
1362 {
1363 /*
1364 * Display it.
1365 */
1366 if (!fOptSorted)
1367 {
1368 for (size_t i = 0; i < machines.size(); ++i)
1369 if (machines[i])
1370 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1371 }
1372 else
1373 {
1374 /*
1375 * Sort the list by name before displaying it.
1376 */
1377 std::vector<std::pair<com::Bstr, IMachine *> > sortedMachines;
1378 for (size_t i = 0; i < machines.size(); ++i)
1379 {
1380 IMachine *pMachine = machines[i];
1381 if (pMachine) /* no idea why we need to do this... */
1382 {
1383 Bstr bstrName;
1384 pMachine->COMGETTER(Name)(bstrName.asOutParam());
1385 sortedMachines.push_back(std::pair<com::Bstr, IMachine *>(bstrName, pMachine));
1386 }
1387 }
1388
1389 std::sort(sortedMachines.begin(), sortedMachines.end());
1390
1391 for (size_t i = 0; i < sortedMachines.size(); ++i)
1392 rc = showVMInfo(pVirtualBox, sortedMachines[i].second, NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1393 }
1394 }
1395 break;
1396 }
1397
1398 case kListRunningVMs:
1399 {
1400 /*
1401 * Get the list of all _running_ VMs
1402 */
1403 com::SafeIfaceArray<IMachine> machines;
1404 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1405 com::SafeArray<MachineState_T> states;
1406 if (SUCCEEDED(rc))
1407 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
1408 if (SUCCEEDED(rc))
1409 {
1410 /*
1411 * Iterate through the collection
1412 */
1413 for (size_t i = 0; i < machines.size(); ++i)
1414 {
1415 if (machines[i])
1416 {
1417 MachineState_T machineState = states[i];
1418 switch (machineState)
1419 {
1420 case MachineState_Running:
1421 case MachineState_Teleporting:
1422 case MachineState_LiveSnapshotting:
1423 case MachineState_Paused:
1424 case MachineState_TeleportingPausedVM:
1425 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1426 break;
1427 default: break; /* Shut up MSC */
1428 }
1429 }
1430 }
1431 }
1432 break;
1433 }
1434
1435 case kListOsTypes:
1436 {
1437 com::SafeIfaceArray<IGuestOSType> coll;
1438 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
1439 if (SUCCEEDED(rc))
1440 {
1441 /*
1442 * Iterate through the collection.
1443 */
1444 for (size_t i = 0; i < coll.size(); ++i)
1445 {
1446 ComPtr<IGuestOSType> guestOS;
1447 guestOS = coll[i];
1448 Bstr guestId;
1449 guestOS->COMGETTER(Id)(guestId.asOutParam());
1450 RTPrintf("ID: %ls\n", guestId.raw());
1451 Bstr guestDescription;
1452 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
1453 RTPrintf("Description: %ls\n", guestDescription.raw());
1454 Bstr familyId;
1455 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
1456 RTPrintf("Family ID: %ls\n", familyId.raw());
1457 Bstr familyDescription;
1458 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
1459 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
1460 BOOL is64Bit;
1461 guestOS->COMGETTER(Is64Bit)(&is64Bit);
1462 RTPrintf("64 bit: %RTbool\n", is64Bit);
1463 RTPrintf("\n");
1464 }
1465 }
1466 break;
1467 }
1468
1469 case kListHostDvds:
1470 {
1471 ComPtr<IHost> host;
1472 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1473 com::SafeIfaceArray<IMedium> coll;
1474 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
1475 if (SUCCEEDED(rc))
1476 {
1477 for (size_t i = 0; i < coll.size(); ++i)
1478 {
1479 ComPtr<IMedium> dvdDrive = coll[i];
1480 Bstr uuid;
1481 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
1482 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1483 Bstr location;
1484 dvdDrive->COMGETTER(Location)(location.asOutParam());
1485 RTPrintf("Name: %ls\n\n", location.raw());
1486 }
1487 }
1488 break;
1489 }
1490
1491 case kListHostFloppies:
1492 {
1493 ComPtr<IHost> host;
1494 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1495 com::SafeIfaceArray<IMedium> coll;
1496 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
1497 if (SUCCEEDED(rc))
1498 {
1499 for (size_t i = 0; i < coll.size(); ++i)
1500 {
1501 ComPtr<IMedium> floppyDrive = coll[i];
1502 Bstr uuid;
1503 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1504 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1505 Bstr location;
1506 floppyDrive->COMGETTER(Location)(location.asOutParam());
1507 RTPrintf("Name: %ls\n\n", location.raw());
1508 }
1509 }
1510 break;
1511 }
1512
1513 case kListInternalNetworks:
1514 rc = listInternalNetworks(pVirtualBox);
1515 break;
1516
1517 case kListBridgedInterfaces:
1518#if defined(VBOX_WITH_NETFLT)
1519 case kListHostOnlyInterfaces:
1520#endif
1521 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1522 break;
1523
1524#if defined(VBOX_WITH_CLOUD_NET)
1525 case kListCloudNetworks:
1526 rc = listCloudNetworks(pVirtualBox);
1527 break;
1528#endif
1529 case kListHostInfo:
1530 rc = listHostInfo(pVirtualBox);
1531 break;
1532
1533 case kListHostCpuIDs:
1534 {
1535 ComPtr<IHost> Host;
1536 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
1537
1538 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
1539 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
1540 static uint32_t const s_auCpuIdRanges[] =
1541 {
1542 UINT32_C(0x00000000), UINT32_C(0x0000007f),
1543 UINT32_C(0x80000000), UINT32_C(0x8000007f),
1544 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
1545 };
1546 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
1547 {
1548 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
1549 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
1550 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
1551 continue;
1552 cLeafs++;
1553 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
1554 {
1555 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
1556 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
1557 }
1558 }
1559 break;
1560 }
1561
1562 case kListHddBackends:
1563 rc = listHddBackends(pVirtualBox);
1564 break;
1565
1566 case kListHdds:
1567 {
1568 com::SafeIfaceArray<IMedium> hdds;
1569 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
1570 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
1571 break;
1572 }
1573
1574 case kListDvds:
1575 {
1576 com::SafeIfaceArray<IMedium> dvds;
1577 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
1578 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
1579 break;
1580 }
1581
1582 case kListFloppies:
1583 {
1584 com::SafeIfaceArray<IMedium> floppies;
1585 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
1586 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
1587 break;
1588 }
1589
1590 case kListUsbHost:
1591 rc = listUsbHost(pVirtualBox);
1592 break;
1593
1594 case kListUsbFilters:
1595 rc = listUsbFilters(pVirtualBox);
1596 break;
1597
1598 case kListSystemProperties:
1599 rc = listSystemProperties(pVirtualBox);
1600 break;
1601
1602 case kListDhcpServers:
1603 rc = listDhcpServers(pVirtualBox);
1604 break;
1605
1606 case kListExtPacks:
1607 rc = listExtensionPacks(pVirtualBox);
1608 break;
1609
1610 case kListGroups:
1611 rc = listGroups(pVirtualBox);
1612 break;
1613
1614 case kListNatNetworks:
1615 {
1616 com::SafeIfaceArray<INATNetwork> nets;
1617 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
1618 for (size_t i = 0; i < nets.size(); ++i)
1619 {
1620 ComPtr<INATNetwork> net = nets[i];
1621 Bstr netName;
1622 net->COMGETTER(NetworkName)(netName.asOutParam());
1623 RTPrintf("NetworkName: %ls\n", netName.raw());
1624 Bstr gateway;
1625 net->COMGETTER(Gateway)(gateway.asOutParam());
1626 RTPrintf("IP: %ls\n", gateway.raw());
1627 Bstr network;
1628 net->COMGETTER(Network)(network.asOutParam());
1629 RTPrintf("Network: %ls\n", network.raw());
1630 BOOL fEnabled;
1631 net->COMGETTER(IPv6Enabled)(&fEnabled);
1632 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
1633 Bstr ipv6prefix;
1634 net->COMGETTER(IPv6Prefix)(ipv6prefix.asOutParam());
1635 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
1636 net->COMGETTER(NeedDhcpServer)(&fEnabled);
1637 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
1638 net->COMGETTER(Enabled)(&fEnabled);
1639 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1640
1641#define PRINT_STRING_ARRAY(title) \
1642 if (strs.size() > 0) \
1643 { \
1644 RTPrintf(title); \
1645 size_t j = 0; \
1646 for (;j < strs.size(); ++j) \
1647 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
1648 }
1649
1650 com::SafeArray<BSTR> strs;
1651
1652 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
1653 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
1654 strs.setNull();
1655
1656 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
1657 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
1658 strs.setNull();
1659
1660 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
1661 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
1662 strs.setNull();
1663
1664#undef PRINT_STRING_ARRAY
1665 RTPrintf("\n");
1666 }
1667 break;
1668 }
1669
1670 case kListVideoInputDevices:
1671 rc = listVideoInputDevices(pVirtualBox);
1672 break;
1673
1674 case kListScreenShotFormats:
1675 rc = listScreenShotFormats(pVirtualBox);
1676 break;
1677
1678 case kListCloudProviders:
1679 rc = listCloudProviders(pVirtualBox);
1680 break;
1681
1682 case kListCloudProfiles:
1683 rc = listCloudProfiles(pVirtualBox, fOptLong);
1684 break;
1685
1686 /* No default here, want gcc warnings. */
1687
1688 } /* end switch */
1689
1690 return rc;
1691}
1692
1693/**
1694 * Handles the 'list' command.
1695 *
1696 * @returns Appropriate exit code.
1697 * @param a Handler argument.
1698 */
1699RTEXITCODE handleList(HandlerArg *a)
1700{
1701 bool fOptLong = false;
1702 bool fOptMultiple = false;
1703 bool fOptSorted = false;
1704 enum enmListType enmOptCommand = kListNotSpecified;
1705
1706 static const RTGETOPTDEF s_aListOptions[] =
1707 {
1708 { "--long", 'l', RTGETOPT_REQ_NOTHING },
1709 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
1710 { "--sorted", 's', RTGETOPT_REQ_NOTHING },
1711 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
1712 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
1713 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
1714 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
1715 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
1716 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
1717 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
1718 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
1719#if defined(VBOX_WITH_NETFLT)
1720 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
1721#endif
1722#if defined(VBOX_WITH_CLOUD_NET)
1723 { "cloudnets", kListCloudNetworks, RTGETOPT_REQ_NOTHING },
1724#endif
1725 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1726 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1727 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
1728 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
1729 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
1730 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
1731 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
1732 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
1733 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
1734 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
1735 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
1736 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
1737 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
1738 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
1739 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
1740 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
1741 { "cloudproviders", kListCloudProviders, RTGETOPT_REQ_NOTHING },
1742 { "cloudprofiles", kListCloudProfiles, RTGETOPT_REQ_NOTHING },
1743 };
1744
1745 int ch;
1746 RTGETOPTUNION ValueUnion;
1747 RTGETOPTSTATE GetState;
1748 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
1749 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1750 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1751 {
1752 switch (ch)
1753 {
1754 case 'l': /* --long */
1755 fOptLong = true;
1756 break;
1757
1758 case 's':
1759 fOptSorted = true;
1760 break;
1761
1762 case 'm':
1763 fOptMultiple = true;
1764 if (enmOptCommand == kListNotSpecified)
1765 break;
1766 ch = enmOptCommand;
1767 RT_FALL_THRU();
1768
1769 case kListVMs:
1770 case kListRunningVMs:
1771 case kListOsTypes:
1772 case kListHostDvds:
1773 case kListHostFloppies:
1774 case kListInternalNetworks:
1775 case kListBridgedInterfaces:
1776#if defined(VBOX_WITH_NETFLT)
1777 case kListHostOnlyInterfaces:
1778#endif
1779#if defined(VBOX_WITH_CLOUD_NET)
1780 case kListCloudNetworks:
1781#endif
1782 case kListHostInfo:
1783 case kListHostCpuIDs:
1784 case kListHddBackends:
1785 case kListHdds:
1786 case kListDvds:
1787 case kListFloppies:
1788 case kListUsbHost:
1789 case kListUsbFilters:
1790 case kListSystemProperties:
1791 case kListDhcpServers:
1792 case kListExtPacks:
1793 case kListGroups:
1794 case kListNatNetworks:
1795 case kListVideoInputDevices:
1796 case kListScreenShotFormats:
1797 case kListCloudProviders:
1798 case kListCloudProfiles:
1799 enmOptCommand = (enum enmListType)ch;
1800 if (fOptMultiple)
1801 {
1802 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, fOptSorted, a->virtualBox);
1803 if (FAILED(hrc))
1804 return RTEXITCODE_FAILURE;
1805 }
1806 break;
1807
1808 case VINF_GETOPT_NOT_OPTION:
1809 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1810
1811 default:
1812 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1813 }
1814 }
1815
1816 /*
1817 * If not in multiple list mode, we have to produce the list now.
1818 */
1819 if (enmOptCommand == kListNotSpecified)
1820 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1821 if (!fOptMultiple)
1822 {
1823 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
1824 if (FAILED(hrc))
1825 return RTEXITCODE_FAILURE;
1826 }
1827
1828 return RTEXITCODE_SUCCESS;
1829}
1830
1831#endif /* !VBOX_ONLY_DOCS */
1832/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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