VirtualBox

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

Last change on this file since 81803 was 81644, checked in by vboxsync, 5 years ago

Main: Removed unused/obsolete/useless portVersion attribute of IUSBDevice.

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

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