VirtualBox

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

Last change on this file since 85708 was 85688, checked in by vboxsync, 4 years ago

Main,FE/VBoxManage+Host: fix build: remove trailing whitespace

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 77.7 KB
Line 
1/* $Id: VBoxManageList.cpp 85688 2020-08-11 12:37:34Z 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 systemProperties->COMGETTER(VBoxUpdateEnabled)(&fValue);
830 RTPrintf("Update check enabled: %s\n", fValue ? "yes" : "no");
831 systemProperties->COMGETTER(VBoxUpdateCount)(&ulValue);
832 RTPrintf("Update check count: %u\n", ulValue);
833 systemProperties->COMGETTER(VBoxUpdateFrequency)(&ulValue);
834 if (ulValue == 0)
835 RTPrintf("Update check frequency: never\n");
836 else if (ulValue == 1)
837 RTPrintf("Update check frequency: every day\n");
838 else
839 RTPrintf("Update check frequency: every %u days\n", ulValue);
840 VBoxUpdateTarget_T enmVBoxUpdateTarget;
841 systemProperties->COMGETTER(VBoxUpdateTarget)(&enmVBoxUpdateTarget);
842 switch (enmVBoxUpdateTarget)
843 {
844 case VBoxUpdateTarget_Stable:
845 psz = "Stable: new minor and maintenance releases";
846 break;
847 case VBoxUpdateTarget_AllReleases:
848 psz = "All releases: new minor, maintenance, and major releases";
849 break;
850 case VBoxUpdateTarget_WithBetas:
851 psz = "With Betas: new minor, maintenance, major, and beta releases";
852 break;
853 default:
854 psz = "Unset";
855 break;
856 }
857 RTPrintf("Update check target: %s\n", psz);
858 systemProperties->COMGETTER(VBoxUpdateLastCheckDate)(str.asOutParam());
859 RTPrintf("Last check date: %ls\n", str.raw());
860
861 return S_OK;
862}
863
864
865/**
866 * Helper for listDhcpServers() that shows a DHCP configuration.
867 */
868static HRESULT showDhcpConfig(ComPtr<IDHCPConfig> ptrConfig)
869{
870 HRESULT hrcRet = S_OK;
871
872 ULONG secs = 0;
873 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MinLeaseTime)(&secs), hrcRet = hrcCheck);
874 if (secs == 0)
875 RTPrintf(" minLeaseTime: default\n");
876 else
877 RTPrintf(" minLeaseTime: %u sec\n", secs);
878
879 secs = 0;
880 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(DefaultLeaseTime)(&secs), hrcRet = hrcCheck);
881 if (secs == 0)
882 RTPrintf(" defaultLeaseTime: default\n");
883 else
884 RTPrintf(" defaultLeaseTime: %u sec\n", secs);
885
886 secs = 0;
887 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MaxLeaseTime)(&secs), hrcRet = hrcCheck);
888 if (secs == 0)
889 RTPrintf(" maxLeaseTime: default\n");
890 else
891 RTPrintf(" maxLeaseTime: %u sec\n", secs);
892
893 com::SafeArray<DHCPOption_T> Options;
894 HRESULT hrc;
895 CHECK_ERROR2_STMT(hrc, ptrConfig, COMGETTER(ForcedOptions(ComSafeArrayAsOutParam(Options))), hrcRet = hrc);
896 if (FAILED(hrc))
897 RTPrintf(" Forced options: %Rhrc\n", hrc);
898 else if (Options.size() == 0)
899 RTPrintf(" Forced options: None\n");
900 else
901 {
902 RTPrintf(" Forced options: ");
903 for (size_t i = 0; i < Options.size(); i++)
904 RTPrintf(i ? ", %u" : "%u", Options[i]);
905 RTPrintf("\n");
906 }
907
908 CHECK_ERROR2_STMT(hrc, ptrConfig, COMGETTER(SuppressedOptions(ComSafeArrayAsOutParam(Options))), hrcRet = hrc);
909 if (FAILED(hrc))
910 RTPrintf(" Suppressed opt.s: %Rhrc\n", hrc);
911 else if (Options.size() == 0)
912 RTPrintf(" Suppressed opts.: None\n");
913 else
914 {
915 RTPrintf(" Suppressed opts.: ");
916 for (size_t i = 0; i < Options.size(); i++)
917 RTPrintf(i ? ", %u" : "%u", Options[i]);
918 RTPrintf("\n");
919 }
920
921 com::SafeArray<DHCPOptionEncoding_T> Encodings;
922 com::SafeArray<BSTR> Values;
923 CHECK_ERROR2_STMT(hrc, ptrConfig, GetAllOptions(ComSafeArrayAsOutParam(Options),
924 ComSafeArrayAsOutParam(Encodings),
925 ComSafeArrayAsOutParam(Values)), hrcRet = hrc);
926 if (FAILED(hrc))
927 RTPrintf(" DHCP options: %Rhrc\n", hrc);
928 else if (Options.size() != Encodings.size() || Options.size() != Values.size())
929 {
930 RTPrintf(" DHCP options: Return count mismatch: %zu, %zu, %zu\n", Options.size(), Encodings.size(), Values.size());
931 hrcRet = E_FAIL;
932 }
933 else if (Options.size() == 0)
934 RTPrintf(" DHCP options: None\n");
935 else
936 for (size_t i = 0; i < Options.size(); i++)
937 {
938 switch (Encodings[i])
939 {
940 case DHCPOptionEncoding_Normal:
941 RTPrintf(" %3d/legacy: %ls\n", Options[i], Values[i]);
942 break;
943 case DHCPOptionEncoding_Hex:
944 RTPrintf(" %3d/hex: %ls\n", Options[i], Values[i]);
945 break;
946 default:
947 RTPrintf(" %3d/%u?: %ls\n", Options[i], Encodings[i], Values[i]);
948 break;
949 }
950 }
951
952 return S_OK;
953}
954
955
956/**
957 * List DHCP servers.
958 *
959 * @returns See produceList.
960 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
961 */
962static HRESULT listDhcpServers(const ComPtr<IVirtualBox> &pVirtualBox)
963{
964 HRESULT hrcRet = S_OK;
965 com::SafeIfaceArray<IDHCPServer> DHCPServers;
966 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers)), hrcCheck);
967 for (size_t i = 0; i < DHCPServers.size(); ++i)
968 {
969 if (i > 0)
970 RTPrintf("\n");
971
972 ComPtr<IDHCPServer> ptrDHCPServer = DHCPServers[i];
973 Bstr bstr;
974 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(NetworkName)(bstr.asOutParam()), hrcRet = hrcCheck);
975 RTPrintf("NetworkName: %ls\n", bstr.raw());
976
977 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(IPAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
978 RTPrintf("Dhcpd IP: %ls\n", bstr.raw());
979
980 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(LowerIP)(bstr.asOutParam()), hrcRet = hrcCheck);
981 RTPrintf("LowerIPAddress: %ls\n", bstr.raw());
982
983 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(UpperIP)(bstr.asOutParam()), hrcRet = hrcCheck);
984 RTPrintf("UpperIPAddress: %ls\n", bstr.raw());
985
986 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(NetworkMask)(bstr.asOutParam()), hrcRet = hrcCheck);
987 RTPrintf("NetworkMask: %ls\n", bstr.raw());
988
989 BOOL fEnabled = FALSE;
990 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(Enabled)(&fEnabled), hrcRet = hrcCheck);
991 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
992
993 /* Global configuration: */
994 RTPrintf("Global Configuration:\n");
995 HRESULT hrc;
996 ComPtr<IDHCPGlobalConfig> ptrGlobal;
997 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(GlobalConfig)(ptrGlobal.asOutParam()), hrcRet = hrc);
998 if (SUCCEEDED(hrc))
999 {
1000 hrc = showDhcpConfig(ptrGlobal);
1001 if (FAILED(hrc))
1002 hrcRet = hrc;
1003 }
1004
1005 /* Group configurations: */
1006 com::SafeIfaceArray<IDHCPGroupConfig> Groups;
1007 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(GroupConfigs)(ComSafeArrayAsOutParam(Groups)), hrcRet = hrc);
1008 if (FAILED(hrc))
1009 RTPrintf("Groups: %Rrc\n", hrc);
1010 else if (Groups.size() == 0)
1011 RTPrintf("Groups: None\n");
1012 else
1013 {
1014 for (size_t iGrp = 0; iGrp < Groups.size(); iGrp++)
1015 {
1016 CHECK_ERROR2I_STMT(Groups[iGrp], COMGETTER(Name)(bstr.asOutParam()), hrcRet = hrcCheck);
1017 RTPrintf("Group: %ls\n", bstr.raw());
1018
1019 com::SafeIfaceArray<IDHCPGroupCondition> Conditions;
1020 CHECK_ERROR2_STMT(hrc, Groups[iGrp], COMGETTER(Conditions)(ComSafeArrayAsOutParam(Conditions)), hrcRet = hrc);
1021 if (FAILED(hrc))
1022 RTPrintf(" Conditions: %Rhrc\n", hrc);
1023 else if (Conditions.size() == 0)
1024 RTPrintf(" Conditions: None\n");
1025 else
1026 for (size_t iCond = 0; iCond < Conditions.size(); iCond++)
1027 {
1028 BOOL fInclusive = TRUE;
1029 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Inclusive)(&fInclusive), hrcRet = hrc);
1030 DHCPGroupConditionType_T enmType = DHCPGroupConditionType_MAC;
1031 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Type)(&enmType), hrcRet = hrc);
1032 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Value)(bstr.asOutParam()), hrcRet = hrc);
1033
1034 RTPrintf(" Conditions: %s %s %ls\n",
1035 fInclusive ? "include" : "exclude",
1036 enmType == DHCPGroupConditionType_MAC ? "MAC "
1037 : enmType == DHCPGroupConditionType_MACWildcard ? "MAC* "
1038 : enmType == DHCPGroupConditionType_vendorClassID ? "VendorCID "
1039 : enmType == DHCPGroupConditionType_vendorClassIDWildcard ? "VendorCID*"
1040 : enmType == DHCPGroupConditionType_userClassID ? "UserCID "
1041 : enmType == DHCPGroupConditionType_userClassIDWildcard ? "UserCID* "
1042 : "!UNKNOWN! ",
1043 bstr.raw());
1044 }
1045
1046 hrc = showDhcpConfig(Groups[iGrp]);
1047 if (FAILED(hrc))
1048 hrcRet = hrc;
1049 }
1050 Groups.setNull();
1051 }
1052
1053 /* Individual host / NIC configurations: */
1054 com::SafeIfaceArray<IDHCPIndividualConfig> Hosts;
1055 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(IndividualConfigs)(ComSafeArrayAsOutParam(Hosts)), hrcRet = hrc);
1056 if (FAILED(hrc))
1057 RTPrintf("Individual Configs: %Rrc\n", hrc);
1058 else if (Hosts.size() == 0)
1059 RTPrintf("Individual Configs: None\n");
1060 else
1061 {
1062 for (size_t iHost = 0; iHost < Hosts.size(); iHost++)
1063 {
1064 DHCPConfigScope_T enmScope = DHCPConfigScope_MAC;
1065 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Scope)(&enmScope), hrcRet = hrcCheck);
1066
1067 if (enmScope == DHCPConfigScope_MAC)
1068 {
1069 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(MACAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
1070 RTPrintf("Individual Config: MAC %ls\n", bstr.raw());
1071 }
1072 else
1073 {
1074 ULONG uSlot = 0;
1075 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Slot)(&uSlot), hrcRet = hrcCheck);
1076 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(MachineId)(bstr.asOutParam()), hrcRet = hrcCheck);
1077 Bstr bstrMACAddress;
1078 hrc = Hosts[iHost]->COMGETTER(MACAddress)(bstrMACAddress.asOutParam()); /* No CHECK_ERROR2 stuff! */
1079 if (SUCCEEDED(hrc))
1080 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %ls\n", bstr.raw(), uSlot, bstrMACAddress.raw());
1081 else
1082 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %Rhrc\n", bstr.raw(), uSlot, hrc);
1083 }
1084
1085 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(FixedAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
1086 if (bstr.isNotEmpty())
1087 RTPrintf(" Fixed Address: %ls\n", bstr.raw());
1088 else
1089 RTPrintf(" Fixed Address: dynamic\n");
1090
1091 hrc = showDhcpConfig(Hosts[iHost]);
1092 if (FAILED(hrc))
1093 hrcRet = hrc;
1094 }
1095 Hosts.setNull();
1096 }
1097 }
1098
1099 return hrcRet;
1100}
1101
1102/**
1103 * List extension packs.
1104 *
1105 * @returns See produceList.
1106 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1107 */
1108static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
1109{
1110 ComObjPtr<IExtPackManager> ptrExtPackMgr;
1111 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
1112
1113 SafeIfaceArray<IExtPack> extPacks;
1114 CHECK_ERROR2I_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
1115 RTPrintf("Extension Packs: %u\n", extPacks.size());
1116
1117 HRESULT hrc = S_OK;
1118 for (size_t i = 0; i < extPacks.size(); i++)
1119 {
1120 /* Read all the properties. */
1121 Bstr bstrName;
1122 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
1123 Bstr bstrDesc;
1124 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
1125 Bstr bstrVersion;
1126 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
1127 ULONG uRevision;
1128 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
1129 Bstr bstrEdition;
1130 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
1131 Bstr bstrVrdeModule;
1132 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
1133 BOOL fUsable;
1134 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
1135 Bstr bstrWhy;
1136 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
1137
1138 /* Display them. */
1139 if (i)
1140 RTPrintf("\n");
1141 RTPrintf("Pack no.%2zu: %ls\n"
1142 "Version: %ls\n"
1143 "Revision: %u\n"
1144 "Edition: %ls\n"
1145 "Description: %ls\n"
1146 "VRDE Module: %ls\n"
1147 "Usable: %RTbool\n"
1148 "Why unusable: %ls\n",
1149 i, bstrName.raw(),
1150 bstrVersion.raw(),
1151 uRevision,
1152 bstrEdition.raw(),
1153 bstrDesc.raw(),
1154 bstrVrdeModule.raw(),
1155 fUsable != FALSE,
1156 bstrWhy.raw());
1157
1158 /* Query plugins and display them. */
1159 }
1160 return hrc;
1161}
1162
1163
1164/**
1165 * List machine groups.
1166 *
1167 * @returns See produceList.
1168 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1169 */
1170static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
1171{
1172 SafeArray<BSTR> groups;
1173 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
1174
1175 for (size_t i = 0; i < groups.size(); i++)
1176 {
1177 RTPrintf("\"%ls\"\n", groups[i]);
1178 }
1179 return S_OK;
1180}
1181
1182
1183/**
1184 * List video capture devices.
1185 *
1186 * @returns See produceList.
1187 * @param pVirtualBox Reference to the IVirtualBox pointer.
1188 */
1189static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> &pVirtualBox)
1190{
1191 HRESULT rc;
1192 ComPtr<IHost> host;
1193 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1194 com::SafeIfaceArray<IHostVideoInputDevice> hostVideoInputDevices;
1195 CHECK_ERROR(host, COMGETTER(VideoInputDevices)(ComSafeArrayAsOutParam(hostVideoInputDevices)));
1196 RTPrintf("Video Input Devices: %u\n", hostVideoInputDevices.size());
1197 for (size_t i = 0; i < hostVideoInputDevices.size(); ++i)
1198 {
1199 ComPtr<IHostVideoInputDevice> p = hostVideoInputDevices[i];
1200 Bstr name;
1201 p->COMGETTER(Name)(name.asOutParam());
1202 Bstr path;
1203 p->COMGETTER(Path)(path.asOutParam());
1204 Bstr alias;
1205 p->COMGETTER(Alias)(alias.asOutParam());
1206 RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
1207 }
1208 return rc;
1209}
1210
1211/**
1212 * List supported screen shot formats.
1213 *
1214 * @returns See produceList.
1215 * @param pVirtualBox Reference to the IVirtualBox pointer.
1216 */
1217static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> &pVirtualBox)
1218{
1219 HRESULT rc = S_OK;
1220 ComPtr<ISystemProperties> systemProperties;
1221 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
1222 com::SafeArray<BitmapFormat_T> formats;
1223 CHECK_ERROR(systemProperties, COMGETTER(ScreenShotFormats)(ComSafeArrayAsOutParam(formats)));
1224
1225 RTPrintf("Supported %d screen shot formats:\n", formats.size());
1226 for (size_t i = 0; i < formats.size(); ++i)
1227 {
1228 uint32_t u32Format = (uint32_t)formats[i];
1229 char szFormat[5];
1230 szFormat[0] = RT_BYTE1(u32Format);
1231 szFormat[1] = RT_BYTE2(u32Format);
1232 szFormat[2] = RT_BYTE3(u32Format);
1233 szFormat[3] = RT_BYTE4(u32Format);
1234 szFormat[4] = 0;
1235 RTPrintf(" BitmapFormat_%s (0x%08X)\n", szFormat, u32Format);
1236 }
1237 return rc;
1238}
1239
1240/**
1241 * List available cloud providers.
1242 *
1243 * @returns See produceList.
1244 * @param pVirtualBox Reference to the IVirtualBox pointer.
1245 */
1246static HRESULT listCloudProviders(const ComPtr<IVirtualBox> &pVirtualBox)
1247{
1248 HRESULT rc = S_OK;
1249 ComPtr<ICloudProviderManager> pCloudProviderManager;
1250 CHECK_ERROR(pVirtualBox, COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()));
1251 com::SafeIfaceArray<ICloudProvider> apCloudProviders;
1252 CHECK_ERROR(pCloudProviderManager, COMGETTER(Providers)(ComSafeArrayAsOutParam(apCloudProviders)));
1253
1254 RTPrintf("Supported %d cloud providers:\n", apCloudProviders.size());
1255 for (size_t i = 0; i < apCloudProviders.size(); ++i)
1256 {
1257 ComPtr<ICloudProvider> pCloudProvider = apCloudProviders[i];
1258 Bstr bstrProviderName;
1259 pCloudProvider->COMGETTER(Name)(bstrProviderName.asOutParam());
1260 RTPrintf("Name: %ls\n", bstrProviderName.raw());
1261 pCloudProvider->COMGETTER(ShortName)(bstrProviderName.asOutParam());
1262 RTPrintf("Short Name: %ls\n", bstrProviderName.raw());
1263 Bstr bstrProviderID;
1264 pCloudProvider->COMGETTER(Id)(bstrProviderID.asOutParam());
1265 RTPrintf("GUID: %ls\n", bstrProviderID.raw());
1266
1267 RTPrintf("\n");
1268 }
1269 return rc;
1270}
1271
1272
1273/**
1274 * List all available cloud profiles (by iterating over the cloud providers).
1275 *
1276 * @returns See produceList.
1277 * @param pVirtualBox Reference to the IVirtualBox pointer.
1278 * @param fOptLong If true, list all profile properties.
1279 */
1280static HRESULT listCloudProfiles(const ComPtr<IVirtualBox> &pVirtualBox, bool fOptLong)
1281{
1282 HRESULT rc = S_OK;
1283 ComPtr<ICloudProviderManager> pCloudProviderManager;
1284 CHECK_ERROR(pVirtualBox, COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()));
1285 com::SafeIfaceArray<ICloudProvider> apCloudProviders;
1286 CHECK_ERROR(pCloudProviderManager, COMGETTER(Providers)(ComSafeArrayAsOutParam(apCloudProviders)));
1287
1288 for (size_t i = 0; i < apCloudProviders.size(); ++i)
1289 {
1290 ComPtr<ICloudProvider> pCloudProvider = apCloudProviders[i];
1291 com::SafeIfaceArray<ICloudProfile> apCloudProfiles;
1292 CHECK_ERROR(pCloudProvider, COMGETTER(Profiles)(ComSafeArrayAsOutParam(apCloudProfiles)));
1293 for (size_t j = 0; j < apCloudProfiles.size(); ++j)
1294 {
1295 ComPtr<ICloudProfile> pCloudProfile = apCloudProfiles[j];
1296 Bstr bstrProfileName;
1297 pCloudProfile->COMGETTER(Name)(bstrProfileName.asOutParam());
1298 RTPrintf("Name: %ls\n", bstrProfileName.raw());
1299 Bstr bstrProviderID;
1300 pCloudProfile->COMGETTER(ProviderId)(bstrProviderID.asOutParam());
1301 RTPrintf("Provider GUID: %ls\n", bstrProviderID.raw());
1302
1303 if (fOptLong)
1304 {
1305 com::SafeArray<BSTR> names;
1306 com::SafeArray<BSTR> values;
1307 pCloudProfile->GetProperties(Bstr().raw(), ComSafeArrayAsOutParam(names), ComSafeArrayAsOutParam(values));
1308 size_t cNames = names.size();
1309 size_t cValues = values.size();
1310 bool fFirst = true;
1311 for (size_t k = 0; k < cNames; k++)
1312 {
1313 Bstr value;
1314 if (k < cValues)
1315 value = values[k];
1316 RTPrintf("%s%ls=%ls\n",
1317 fFirst ? "Property: " : " ",
1318 names[k], value.raw());
1319 fFirst = false;
1320 }
1321 }
1322
1323 RTPrintf("\n");
1324 }
1325 }
1326 return rc;
1327}
1328
1329static HRESULT displayCPUProfile(ICPUProfile *pProfile, size_t idx, int cchIdx, bool fOptLong, HRESULT hrc)
1330{
1331 /* Retrieve the attributes needed for both long and short display. */
1332 Bstr bstrName;
1333 CHECK_ERROR2I_RET(pProfile, COMGETTER(Name)(bstrName.asOutParam()), hrcCheck);
1334
1335 CPUArchitecture_T enmArchitecture = CPUArchitecture_Any;
1336 CHECK_ERROR2I_RET(pProfile, COMGETTER(Architecture)(&enmArchitecture), hrcCheck);
1337 const char *pszArchitecture = "???";
1338 switch (enmArchitecture)
1339 {
1340 case CPUArchitecture_x86: pszArchitecture = "x86"; break;
1341 case CPUArchitecture_AMD64: pszArchitecture = "AMD64"; break;
1342
1343#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
1344 case CPUArchitecture_32BitHack:
1345#endif
1346 case CPUArchitecture_Any:
1347 break;
1348 }
1349
1350 /* Print what we've got. */
1351 if (!fOptLong)
1352 RTPrintf("#%0*zu: %ls [%s]\n", cchIdx, idx, bstrName.raw(), pszArchitecture);
1353 else
1354 {
1355 RTPrintf("CPU Profile #%02zu:\n", idx);
1356 RTPrintf(" Architecture: %s\n", pszArchitecture);
1357 RTPrintf(" Name: %ls\n", bstrName.raw());
1358 CHECK_ERROR2I_RET(pProfile, COMGETTER(FullName)(bstrName.asOutParam()), hrcCheck);
1359 RTPrintf(" Full Name: %ls\n", bstrName.raw());
1360 }
1361 return hrc;
1362}
1363
1364
1365/**
1366 * List all CPU profiles.
1367 *
1368 * @returns See produceList.
1369 * @param ptrVirtualBox Reference to the smart IVirtualBox pointer.
1370 * @param fOptLong If true, list all profile properties.
1371 * @param fOptSorted Sort the output if true, otherwise display in
1372 * system order.
1373 */
1374static HRESULT listCPUProfiles(const ComPtr<IVirtualBox> &ptrVirtualBox, bool fOptLong, bool fOptSorted)
1375{
1376 ComPtr<ISystemProperties> ptrSysProps;
1377 CHECK_ERROR2I_RET(ptrVirtualBox, COMGETTER(SystemProperties)(ptrSysProps.asOutParam()), hrcCheck);
1378 com::SafeIfaceArray<ICPUProfile> aCPUProfiles;
1379 CHECK_ERROR2I_RET(ptrSysProps, GetCPUProfiles(CPUArchitecture_Any, Bstr().raw(),
1380 ComSafeArrayAsOutParam(aCPUProfiles)), hrcCheck);
1381
1382 int const cchIdx = 1 + (aCPUProfiles.size() >= 10) + (aCPUProfiles.size() >= 100);
1383
1384 HRESULT hrc = S_OK;
1385 if (!fOptSorted)
1386 for (size_t i = 0; i < aCPUProfiles.size(); i++)
1387 hrc = displayCPUProfile(aCPUProfiles[i], i, cchIdx, fOptLong, hrc);
1388 else
1389 {
1390 std::vector<std::pair<com::Bstr, ICPUProfile *> > vecSortedProfiles;
1391 for (size_t i = 0; i < aCPUProfiles.size(); ++i)
1392 {
1393 Bstr bstrName;
1394 CHECK_ERROR2I_RET(aCPUProfiles[i], COMGETTER(Name)(bstrName.asOutParam()), hrcCheck);
1395 try
1396 {
1397 vecSortedProfiles.push_back(std::pair<com::Bstr, ICPUProfile *>(bstrName, aCPUProfiles[i]));
1398 }
1399 catch (std::bad_alloc &)
1400 {
1401 return E_OUTOFMEMORY;
1402 }
1403 }
1404
1405 std::sort(vecSortedProfiles.begin(), vecSortedProfiles.end());
1406
1407 for (size_t i = 0; i < vecSortedProfiles.size(); i++)
1408 hrc = displayCPUProfile(vecSortedProfiles[i].second, i, cchIdx, fOptLong, hrc);
1409 }
1410
1411 return hrc;
1412}
1413
1414
1415/**
1416 * The type of lists we can produce.
1417 */
1418enum ListType_T
1419{
1420 kListNotSpecified = 1000,
1421 kListVMs,
1422 kListRunningVMs,
1423 kListOsTypes,
1424 kListHostDvds,
1425 kListHostFloppies,
1426 kListInternalNetworks,
1427 kListBridgedInterfaces,
1428#if defined(VBOX_WITH_NETFLT)
1429 kListHostOnlyInterfaces,
1430#endif
1431#if defined(VBOX_WITH_CLOUD_NET)
1432 kListCloudNetworks,
1433#endif
1434 kListHostCpuIDs,
1435 kListHostInfo,
1436 kListHddBackends,
1437 kListHdds,
1438 kListDvds,
1439 kListFloppies,
1440 kListUsbHost,
1441 kListUsbFilters,
1442 kListSystemProperties,
1443 kListDhcpServers,
1444 kListExtPacks,
1445 kListGroups,
1446 kListNatNetworks,
1447 kListVideoInputDevices,
1448 kListScreenShotFormats,
1449 kListCloudProviders,
1450 kListCloudProfiles,
1451 kListCPUProfiles
1452};
1453
1454
1455/**
1456 * Produces the specified listing.
1457 *
1458 * @returns S_OK or some COM error code that has been reported in full.
1459 * @param enmList The list to produce.
1460 * @param fOptLong Long (@c true) or short list format.
1461 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1462 */
1463static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
1464{
1465 HRESULT rc = S_OK;
1466 switch (enmCommand)
1467 {
1468 case kListNotSpecified:
1469 AssertFailed();
1470 return E_FAIL;
1471
1472 case kListVMs:
1473 {
1474 /*
1475 * Get the list of all registered VMs
1476 */
1477 com::SafeIfaceArray<IMachine> machines;
1478 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1479 if (SUCCEEDED(rc))
1480 {
1481 /*
1482 * Display it.
1483 */
1484 if (!fOptSorted)
1485 {
1486 for (size_t i = 0; i < machines.size(); ++i)
1487 if (machines[i])
1488 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1489 }
1490 else
1491 {
1492 /*
1493 * Sort the list by name before displaying it.
1494 */
1495 std::vector<std::pair<com::Bstr, IMachine *> > sortedMachines;
1496 for (size_t i = 0; i < machines.size(); ++i)
1497 {
1498 IMachine *pMachine = machines[i];
1499 if (pMachine) /* no idea why we need to do this... */
1500 {
1501 Bstr bstrName;
1502 pMachine->COMGETTER(Name)(bstrName.asOutParam());
1503 sortedMachines.push_back(std::pair<com::Bstr, IMachine *>(bstrName, pMachine));
1504 }
1505 }
1506
1507 std::sort(sortedMachines.begin(), sortedMachines.end());
1508
1509 for (size_t i = 0; i < sortedMachines.size(); ++i)
1510 rc = showVMInfo(pVirtualBox, sortedMachines[i].second, NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1511 }
1512 }
1513 break;
1514 }
1515
1516 case kListRunningVMs:
1517 {
1518 /*
1519 * Get the list of all _running_ VMs
1520 */
1521 com::SafeIfaceArray<IMachine> machines;
1522 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1523 com::SafeArray<MachineState_T> states;
1524 if (SUCCEEDED(rc))
1525 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
1526 if (SUCCEEDED(rc))
1527 {
1528 /*
1529 * Iterate through the collection
1530 */
1531 for (size_t i = 0; i < machines.size(); ++i)
1532 {
1533 if (machines[i])
1534 {
1535 MachineState_T machineState = states[i];
1536 switch (machineState)
1537 {
1538 case MachineState_Running:
1539 case MachineState_Teleporting:
1540 case MachineState_LiveSnapshotting:
1541 case MachineState_Paused:
1542 case MachineState_TeleportingPausedVM:
1543 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1544 break;
1545 default: break; /* Shut up MSC */
1546 }
1547 }
1548 }
1549 }
1550 break;
1551 }
1552
1553 case kListOsTypes:
1554 {
1555 com::SafeIfaceArray<IGuestOSType> coll;
1556 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
1557 if (SUCCEEDED(rc))
1558 {
1559 /*
1560 * Iterate through the collection.
1561 */
1562 for (size_t i = 0; i < coll.size(); ++i)
1563 {
1564 ComPtr<IGuestOSType> guestOS;
1565 guestOS = coll[i];
1566 Bstr guestId;
1567 guestOS->COMGETTER(Id)(guestId.asOutParam());
1568 RTPrintf("ID: %ls\n", guestId.raw());
1569 Bstr guestDescription;
1570 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
1571 RTPrintf("Description: %ls\n", guestDescription.raw());
1572 Bstr familyId;
1573 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
1574 RTPrintf("Family ID: %ls\n", familyId.raw());
1575 Bstr familyDescription;
1576 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
1577 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
1578 BOOL is64Bit;
1579 guestOS->COMGETTER(Is64Bit)(&is64Bit);
1580 RTPrintf("64 bit: %RTbool\n", is64Bit);
1581 RTPrintf("\n");
1582 }
1583 }
1584 break;
1585 }
1586
1587 case kListHostDvds:
1588 {
1589 ComPtr<IHost> host;
1590 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1591 com::SafeIfaceArray<IMedium> coll;
1592 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
1593 if (SUCCEEDED(rc))
1594 {
1595 for (size_t i = 0; i < coll.size(); ++i)
1596 {
1597 ComPtr<IMedium> dvdDrive = coll[i];
1598 Bstr uuid;
1599 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
1600 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1601 Bstr location;
1602 dvdDrive->COMGETTER(Location)(location.asOutParam());
1603 RTPrintf("Name: %ls\n\n", location.raw());
1604 }
1605 }
1606 break;
1607 }
1608
1609 case kListHostFloppies:
1610 {
1611 ComPtr<IHost> host;
1612 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1613 com::SafeIfaceArray<IMedium> coll;
1614 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
1615 if (SUCCEEDED(rc))
1616 {
1617 for (size_t i = 0; i < coll.size(); ++i)
1618 {
1619 ComPtr<IMedium> floppyDrive = coll[i];
1620 Bstr uuid;
1621 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1622 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1623 Bstr location;
1624 floppyDrive->COMGETTER(Location)(location.asOutParam());
1625 RTPrintf("Name: %ls\n\n", location.raw());
1626 }
1627 }
1628 break;
1629 }
1630
1631 case kListInternalNetworks:
1632 rc = listInternalNetworks(pVirtualBox);
1633 break;
1634
1635 case kListBridgedInterfaces:
1636#if defined(VBOX_WITH_NETFLT)
1637 case kListHostOnlyInterfaces:
1638#endif
1639 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1640 break;
1641
1642#if defined(VBOX_WITH_CLOUD_NET)
1643 case kListCloudNetworks:
1644 rc = listCloudNetworks(pVirtualBox);
1645 break;
1646#endif
1647 case kListHostInfo:
1648 rc = listHostInfo(pVirtualBox);
1649 break;
1650
1651 case kListHostCpuIDs:
1652 {
1653 ComPtr<IHost> Host;
1654 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
1655
1656 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
1657 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
1658 static uint32_t const s_auCpuIdRanges[] =
1659 {
1660 UINT32_C(0x00000000), UINT32_C(0x0000007f),
1661 UINT32_C(0x80000000), UINT32_C(0x8000007f),
1662 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
1663 };
1664 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
1665 {
1666 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
1667 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
1668 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
1669 continue;
1670 cLeafs++;
1671 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
1672 {
1673 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
1674 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
1675 }
1676 }
1677 break;
1678 }
1679
1680 case kListHddBackends:
1681 rc = listHddBackends(pVirtualBox);
1682 break;
1683
1684 case kListHdds:
1685 {
1686 com::SafeIfaceArray<IMedium> hdds;
1687 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
1688 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
1689 break;
1690 }
1691
1692 case kListDvds:
1693 {
1694 com::SafeIfaceArray<IMedium> dvds;
1695 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
1696 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
1697 break;
1698 }
1699
1700 case kListFloppies:
1701 {
1702 com::SafeIfaceArray<IMedium> floppies;
1703 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
1704 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
1705 break;
1706 }
1707
1708 case kListUsbHost:
1709 rc = listUsbHost(pVirtualBox);
1710 break;
1711
1712 case kListUsbFilters:
1713 rc = listUsbFilters(pVirtualBox);
1714 break;
1715
1716 case kListSystemProperties:
1717 rc = listSystemProperties(pVirtualBox);
1718 break;
1719
1720 case kListDhcpServers:
1721 rc = listDhcpServers(pVirtualBox);
1722 break;
1723
1724 case kListExtPacks:
1725 rc = listExtensionPacks(pVirtualBox);
1726 break;
1727
1728 case kListGroups:
1729 rc = listGroups(pVirtualBox);
1730 break;
1731
1732 case kListNatNetworks:
1733 {
1734 com::SafeIfaceArray<INATNetwork> nets;
1735 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
1736 for (size_t i = 0; i < nets.size(); ++i)
1737 {
1738 ComPtr<INATNetwork> net = nets[i];
1739 Bstr netName;
1740 net->COMGETTER(NetworkName)(netName.asOutParam());
1741 RTPrintf("NetworkName: %ls\n", netName.raw());
1742 Bstr gateway;
1743 net->COMGETTER(Gateway)(gateway.asOutParam());
1744 RTPrintf("IP: %ls\n", gateway.raw());
1745 Bstr network;
1746 net->COMGETTER(Network)(network.asOutParam());
1747 RTPrintf("Network: %ls\n", network.raw());
1748 BOOL fEnabled;
1749 net->COMGETTER(IPv6Enabled)(&fEnabled);
1750 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
1751 Bstr ipv6prefix;
1752 net->COMGETTER(IPv6Prefix)(ipv6prefix.asOutParam());
1753 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
1754 net->COMGETTER(NeedDhcpServer)(&fEnabled);
1755 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
1756 net->COMGETTER(Enabled)(&fEnabled);
1757 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1758
1759#define PRINT_STRING_ARRAY(title) \
1760 if (strs.size() > 0) \
1761 { \
1762 RTPrintf(title); \
1763 size_t j = 0; \
1764 for (;j < strs.size(); ++j) \
1765 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
1766 }
1767
1768 com::SafeArray<BSTR> strs;
1769
1770 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
1771 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
1772 strs.setNull();
1773
1774 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
1775 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
1776 strs.setNull();
1777
1778 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
1779 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
1780 strs.setNull();
1781
1782#undef PRINT_STRING_ARRAY
1783 RTPrintf("\n");
1784 }
1785 break;
1786 }
1787
1788 case kListVideoInputDevices:
1789 rc = listVideoInputDevices(pVirtualBox);
1790 break;
1791
1792 case kListScreenShotFormats:
1793 rc = listScreenShotFormats(pVirtualBox);
1794 break;
1795
1796 case kListCloudProviders:
1797 rc = listCloudProviders(pVirtualBox);
1798 break;
1799
1800 case kListCloudProfiles:
1801 rc = listCloudProfiles(pVirtualBox, fOptLong);
1802 break;
1803
1804 case kListCPUProfiles:
1805 rc = listCPUProfiles(pVirtualBox, fOptLong, fOptSorted);
1806 break;
1807
1808 /* No default here, want gcc warnings. */
1809
1810 } /* end switch */
1811
1812 return rc;
1813}
1814
1815/**
1816 * Handles the 'list' command.
1817 *
1818 * @returns Appropriate exit code.
1819 * @param a Handler argument.
1820 */
1821RTEXITCODE handleList(HandlerArg *a)
1822{
1823 bool fOptLong = false;
1824 bool fOptMultiple = false;
1825 bool fOptSorted = false;
1826 enum ListType_T enmOptCommand = kListNotSpecified;
1827
1828 static const RTGETOPTDEF s_aListOptions[] =
1829 {
1830 { "--long", 'l', RTGETOPT_REQ_NOTHING },
1831 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
1832 { "--sorted", 's', RTGETOPT_REQ_NOTHING },
1833 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
1834 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
1835 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
1836 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
1837 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
1838 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
1839 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
1840 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
1841#if defined(VBOX_WITH_NETFLT)
1842 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
1843#endif
1844#if defined(VBOX_WITH_CLOUD_NET)
1845 { "cloudnets", kListCloudNetworks, RTGETOPT_REQ_NOTHING },
1846#endif
1847 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1848 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1849 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
1850 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
1851 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
1852 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
1853 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
1854 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
1855 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
1856 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
1857 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
1858 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
1859 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
1860 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
1861 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
1862 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
1863 { "cloudproviders", kListCloudProviders, RTGETOPT_REQ_NOTHING },
1864 { "cloudprofiles", kListCloudProfiles, RTGETOPT_REQ_NOTHING },
1865 { "cpu-profiles", kListCPUProfiles, RTGETOPT_REQ_NOTHING },
1866 };
1867
1868 int ch;
1869 RTGETOPTUNION ValueUnion;
1870 RTGETOPTSTATE GetState;
1871 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
1872 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1873 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1874 {
1875 switch (ch)
1876 {
1877 case 'l': /* --long */
1878 fOptLong = true;
1879 break;
1880
1881 case 's':
1882 fOptSorted = true;
1883 break;
1884
1885 case 'm':
1886 fOptMultiple = true;
1887 if (enmOptCommand == kListNotSpecified)
1888 break;
1889 ch = enmOptCommand;
1890 RT_FALL_THRU();
1891
1892 case kListVMs:
1893 case kListRunningVMs:
1894 case kListOsTypes:
1895 case kListHostDvds:
1896 case kListHostFloppies:
1897 case kListInternalNetworks:
1898 case kListBridgedInterfaces:
1899#if defined(VBOX_WITH_NETFLT)
1900 case kListHostOnlyInterfaces:
1901#endif
1902#if defined(VBOX_WITH_CLOUD_NET)
1903 case kListCloudNetworks:
1904#endif
1905 case kListHostInfo:
1906 case kListHostCpuIDs:
1907 case kListHddBackends:
1908 case kListHdds:
1909 case kListDvds:
1910 case kListFloppies:
1911 case kListUsbHost:
1912 case kListUsbFilters:
1913 case kListSystemProperties:
1914 case kListDhcpServers:
1915 case kListExtPacks:
1916 case kListGroups:
1917 case kListNatNetworks:
1918 case kListVideoInputDevices:
1919 case kListScreenShotFormats:
1920 case kListCloudProviders:
1921 case kListCloudProfiles:
1922 case kListCPUProfiles:
1923 enmOptCommand = (enum ListType_T)ch;
1924 if (fOptMultiple)
1925 {
1926 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
1927 if (FAILED(hrc))
1928 return RTEXITCODE_FAILURE;
1929 }
1930 break;
1931
1932 case VINF_GETOPT_NOT_OPTION:
1933 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1934
1935 default:
1936 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1937 }
1938 }
1939
1940 /*
1941 * If not in multiple list mode, we have to produce the list now.
1942 */
1943 if (enmOptCommand == kListNotSpecified)
1944 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1945 if (!fOptMultiple)
1946 {
1947 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
1948 if (FAILED(hrc))
1949 return RTEXITCODE_FAILURE;
1950 }
1951
1952 return RTEXITCODE_SUCCESS;
1953}
1954
1955#endif /* !VBOX_ONLY_DOCS */
1956/* 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