VirtualBox

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

Last change on this file since 85889 was 85769, checked in by vboxsync, 5 years ago

Main: bugref:9618 Added Main/API support for AMD-V Virtualized VMSAVE/VMLOAD hardware virtualization feature.

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