VirtualBox

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

Last change on this file since 71586 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.9 KB
Line 
1/* $Id: VBoxManageList.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 }
56 return "unknown";
57}
58
59static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
60{
61 switch (enmStatus)
62 {
63 case HostNetworkInterfaceStatus_Up: return "Up";
64 case HostNetworkInterfaceStatus_Down: return "Down";
65 case HostNetworkInterfaceStatus_Unknown: return "Unknown";
66 }
67 return "unknown";
68}
69#endif /* VBOX_WITH_HOSTNETIF_API */
70
71static const char*getDeviceTypeText(DeviceType_T enmType)
72{
73 switch (enmType)
74 {
75 case DeviceType_HardDisk: return "HardDisk";
76 case DeviceType_DVD: return "DVD";
77 case DeviceType_Floppy: return "Floppy";
78 /* Make MSC happy */
79 case DeviceType_Null: return "Null";
80 case DeviceType_Network: return "Network";
81 case DeviceType_USB: return "USB";
82 case DeviceType_SharedFolder: return "SharedFolder";
83 case DeviceType_Graphics3D: return "Graphics3D";
84 }
85 return "Unknown";
86}
87
88
89/**
90 * List internal networks.
91 *
92 * @returns See produceList.
93 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
94 */
95static HRESULT listInternalNetworks(const ComPtr<IVirtualBox> pVirtualBox)
96{
97 HRESULT rc;
98 com::SafeArray<BSTR> internalNetworks;
99 CHECK_ERROR(pVirtualBox, COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks)));
100 for (size_t i = 0; i < internalNetworks.size(); ++i)
101 {
102 RTPrintf("Name: %ls\n", internalNetworks[i]);
103 }
104 return rc;
105}
106
107
108/**
109 * List network interfaces information (bridged/host only).
110 *
111 * @returns See produceList.
112 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
113 * @param fIsBridged Selects between listing host interfaces (for
114 * use with bridging) or host only interfaces.
115 */
116static HRESULT listNetworkInterfaces(const ComPtr<IVirtualBox> pVirtualBox,
117 bool fIsBridged)
118{
119 HRESULT rc;
120 ComPtr<IHost> host;
121 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
122 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
123#if defined(VBOX_WITH_NETFLT)
124 if (fIsBridged)
125 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
126 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
127 else
128 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
129 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
130#else
131 RT_NOREF(fIsBridged);
132 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
133#endif
134 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
135 {
136 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
137#ifndef VBOX_WITH_HOSTNETIF_API
138 Bstr interfaceName;
139 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
140 RTPrintf("Name: %ls\n", interfaceName.raw());
141 Guid interfaceGuid;
142 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
143 RTPrintf("GUID: %ls\n\n", Bstr(interfaceGuid.toString()).raw());
144#else /* VBOX_WITH_HOSTNETIF_API */
145 Bstr interfaceName;
146 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
147 RTPrintf("Name: %ls\n", interfaceName.raw());
148 Bstr interfaceGuid;
149 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
150 RTPrintf("GUID: %ls\n", interfaceGuid.raw());
151 BOOL bDHCPEnabled;
152 networkInterface->COMGETTER(DHCPEnabled)(&bDHCPEnabled);
153 RTPrintf("DHCP: %s\n", bDHCPEnabled ? "Enabled" : "Disabled");
154
155 Bstr IPAddress;
156 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
157 RTPrintf("IPAddress: %ls\n", IPAddress.raw());
158 Bstr NetworkMask;
159 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
160 RTPrintf("NetworkMask: %ls\n", NetworkMask.raw());
161 Bstr IPV6Address;
162 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
163 RTPrintf("IPV6Address: %ls\n", IPV6Address.raw());
164 ULONG IPV6NetworkMaskPrefixLength;
165 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
166 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
167 Bstr HardwareAddress;
168 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
169 RTPrintf("HardwareAddress: %ls\n", HardwareAddress.raw());
170 HostNetworkInterfaceMediumType_T Type;
171 networkInterface->COMGETTER(MediumType)(&Type);
172 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
173 BOOL fWireless;
174 networkInterface->COMGETTER(Wireless)(&fWireless);
175 RTPrintf("Wireless: %s\n", fWireless ? "Yes" : "No");
176 HostNetworkInterfaceStatus_T Status;
177 networkInterface->COMGETTER(Status)(&Status);
178 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
179 Bstr netName;
180 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
181 RTPrintf("VBoxNetworkName: %ls\n\n", netName.raw());
182#endif
183 }
184 return rc;
185}
186
187
188/**
189 * List host information.
190 *
191 * @returns See produceList.
192 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
193 */
194static HRESULT listHostInfo(const ComPtr<IVirtualBox> pVirtualBox)
195{
196 static struct
197 {
198 ProcessorFeature_T feature;
199 const char *pszName;
200 } features[]
201 =
202 {
203 { ProcessorFeature_HWVirtEx, "HW virtualization" },
204 { ProcessorFeature_PAE, "PAE" },
205 { ProcessorFeature_LongMode, "long mode" },
206 { ProcessorFeature_NestedPaging, "nested paging" },
207 };
208 HRESULT rc;
209 ComPtr<IHost> Host;
210 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
211
212 RTPrintf("Host Information:\n\n");
213
214 LONG64 u64UtcTime = 0;
215 CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
216 RTTIMESPEC timeSpec;
217 char szTime[32];
218 RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
219
220 ULONG processorOnlineCount = 0;
221 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
222 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
223 ULONG processorCount = 0;
224 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
225 RTPrintf("Processor count: %lu\n", processorCount);
226 ULONG processorOnlineCoreCount = 0;
227 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCoreCount)(&processorOnlineCoreCount));
228 RTPrintf("Processor online core count: %lu\n", processorOnlineCoreCount);
229 ULONG processorCoreCount = 0;
230 CHECK_ERROR(Host, COMGETTER(ProcessorCoreCount)(&processorCoreCount));
231 RTPrintf("Processor core count: %lu\n", processorCoreCount);
232 for (unsigned i = 0; i < RT_ELEMENTS(features); i++)
233 {
234 BOOL supported;
235 CHECK_ERROR(Host, GetProcessorFeature(features[i].feature, &supported));
236 RTPrintf("Processor supports %s: %s\n", features[i].pszName, supported ? "yes" : "no");
237 }
238 for (ULONG i = 0; i < processorCount; i++)
239 {
240 ULONG processorSpeed = 0;
241 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
242 if (processorSpeed)
243 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
244 else
245 RTPrintf("Processor#%u speed: unknown\n", i);
246 Bstr processorDescription;
247 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
248 RTPrintf("Processor#%u description: %ls\n", i, processorDescription.raw());
249 }
250
251 ULONG memorySize = 0;
252 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
253 RTPrintf("Memory size: %lu MByte\n", memorySize);
254
255 ULONG memoryAvailable = 0;
256 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
257 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
258
259 Bstr operatingSystem;
260 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
261 RTPrintf("Operating system: %ls\n", operatingSystem.raw());
262
263 Bstr oSVersion;
264 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
265 RTPrintf("Operating system version: %ls\n", oSVersion.raw());
266 return rc;
267}
268
269
270/**
271 * List media information.
272 *
273 * @returns See produceList.
274 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
275 * @param aMedia Medium objects to list information for.
276 * @param pszParentUUIDStr String with the parent UUID string (or "base").
277 * @param fOptLong Long (@c true) or short list format.
278 */
279static HRESULT listMedia(const ComPtr<IVirtualBox> pVirtualBox,
280 const com::SafeIfaceArray<IMedium> &aMedia,
281 const char *pszParentUUIDStr,
282 bool fOptLong)
283{
284 HRESULT rc = S_OK;
285 for (size_t i = 0; i < aMedia.size(); ++i)
286 {
287 ComPtr<IMedium> pMedium = aMedia[i];
288
289 rc = showMediumInfo(pVirtualBox, pMedium, pszParentUUIDStr, fOptLong);
290
291 RTPrintf("\n");
292
293 com::SafeIfaceArray<IMedium> children;
294 CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
295 if (children.size() > 0)
296 {
297 Bstr uuid;
298 pMedium->COMGETTER(Id)(uuid.asOutParam());
299
300 // depth first listing of child media
301 rc = listMedia(pVirtualBox, children, Utf8Str(uuid).c_str(), fOptLong);
302 }
303 }
304
305 return rc;
306}
307
308
309/**
310 * List virtual image backends.
311 *
312 * @returns See produceList.
313 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
314 */
315static HRESULT listHddBackends(const ComPtr<IVirtualBox> pVirtualBox)
316{
317 HRESULT rc;
318 ComPtr<ISystemProperties> systemProperties;
319 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
320 com::SafeIfaceArray<IMediumFormat> mediumFormats;
321 CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
322
323 RTPrintf("Supported hard disk backends:\n\n");
324 for (size_t i = 0; i < mediumFormats.size(); ++i)
325 {
326 /* General information */
327 Bstr id;
328 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
329
330 Bstr description;
331 CHECK_ERROR(mediumFormats[i],
332 COMGETTER(Name)(description.asOutParam()));
333
334 ULONG caps = 0;
335 com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap;
336 CHECK_ERROR(mediumFormats[i],
337 COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap)));
338 for (ULONG j = 0; j < mediumFormatCap.size(); j++)
339 caps |= mediumFormatCap[j];
340
341
342 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
343 i, id.raw(), description.raw(), caps);
344
345 /* File extensions */
346 com::SafeArray<BSTR> fileExtensions;
347 com::SafeArray<DeviceType_T> deviceTypes;
348 CHECK_ERROR(mediumFormats[i],
349 DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
350 for (size_t j = 0; j < fileExtensions.size(); ++j)
351 {
352 RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
353 if (j != fileExtensions.size()-1)
354 RTPrintf(",");
355 }
356 RTPrintf("'");
357
358 /* Configuration keys */
359 com::SafeArray<BSTR> propertyNames;
360 com::SafeArray<BSTR> propertyDescriptions;
361 com::SafeArray<DataType_T> propertyTypes;
362 com::SafeArray<ULONG> propertyFlags;
363 com::SafeArray<BSTR> propertyDefaults;
364 CHECK_ERROR(mediumFormats[i],
365 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
366 ComSafeArrayAsOutParam(propertyDescriptions),
367 ComSafeArrayAsOutParam(propertyTypes),
368 ComSafeArrayAsOutParam(propertyFlags),
369 ComSafeArrayAsOutParam(propertyDefaults)));
370
371 RTPrintf(" properties=(");
372 if (propertyNames.size() > 0)
373 {
374 for (size_t j = 0; j < propertyNames.size(); ++j)
375 {
376 RTPrintf("\n name='%ls' desc='%ls' type=",
377 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
378 switch (propertyTypes[j])
379 {
380 case DataType_Int32: RTPrintf("int"); break;
381 case DataType_Int8: RTPrintf("byte"); break;
382 case DataType_String: RTPrintf("string"); break;
383 }
384 RTPrintf(" flags=%#04x", propertyFlags[j]);
385 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
386 if (j != propertyNames.size()-1)
387 RTPrintf(", ");
388 }
389 }
390 RTPrintf(")\n");
391 }
392 return rc;
393}
394
395
396/**
397 * List USB devices attached to the host.
398 *
399 * @returns See produceList.
400 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
401 */
402static HRESULT listUsbHost(const ComPtr<IVirtualBox> &pVirtualBox)
403{
404 HRESULT rc;
405 ComPtr<IHost> Host;
406 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
407
408 SafeIfaceArray<IHostUSBDevice> CollPtr;
409 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
410
411 RTPrintf("Host USB Devices:\n\n");
412
413 if (CollPtr.size() == 0)
414 {
415 RTPrintf("<none>\n\n");
416 }
417 else
418 {
419 for (size_t i = 0; i < CollPtr.size(); ++i)
420 {
421 ComPtr<IHostUSBDevice> dev = CollPtr[i];
422
423 /* Query info. */
424 Bstr id;
425 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
426 USHORT usVendorId;
427 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
428 USHORT usProductId;
429 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
430 USHORT bcdRevision;
431 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
432 USHORT usPort;
433 CHECK_ERROR_RET(dev, COMGETTER(Port)(&usPort), 1);
434 USHORT usVersion;
435 CHECK_ERROR_RET(dev, COMGETTER(Version)(&usVersion), 1);
436 USHORT usPortVersion;
437 CHECK_ERROR_RET(dev, COMGETTER(PortVersion)(&usPortVersion), 1);
438 USBConnectionSpeed_T enmSpeed;
439 CHECK_ERROR_RET(dev, COMGETTER(Speed)(&enmSpeed), 1);
440
441 RTPrintf("UUID: %s\n"
442 "VendorId: %#06x (%04X)\n"
443 "ProductId: %#06x (%04X)\n"
444 "Revision: %u.%u (%02u%02u)\n"
445 "Port: %u\n",
446 Utf8Str(id).c_str(),
447 usVendorId, usVendorId, usProductId, usProductId,
448 bcdRevision >> 8, bcdRevision & 0xff,
449 bcdRevision >> 8, bcdRevision & 0xff,
450 usPort);
451
452 const char *pszSpeed = "?";
453 switch (enmSpeed)
454 {
455 case USBConnectionSpeed_Low:
456 pszSpeed = "Low";
457 break;
458 case USBConnectionSpeed_Full:
459 pszSpeed = "Full";
460 break;
461 case USBConnectionSpeed_High:
462 pszSpeed = "High";
463 break;
464 case USBConnectionSpeed_Super:
465 pszSpeed = "Super";
466 break;
467 case USBConnectionSpeed_SuperPlus:
468 pszSpeed = "SuperPlus";
469 break;
470 default:
471 ASSERT(false);
472 break;
473 }
474
475 RTPrintf("USB version/speed: %u/%s\n", usVersion, pszSpeed);
476
477 /* optional stuff. */
478 SafeArray<BSTR> CollDevInfo;
479 Bstr bstr;
480 CHECK_ERROR_RET(dev, COMGETTER(DeviceInfo)(ComSafeArrayAsOutParam(CollDevInfo)), 1);
481 if (CollDevInfo.size() >= 1)
482 bstr = Bstr(CollDevInfo[0]);
483 if (!bstr.isEmpty())
484 RTPrintf("Manufacturer: %ls\n", bstr.raw());
485 if (CollDevInfo.size() >= 2)
486 bstr = Bstr(CollDevInfo[1]);
487 if (!bstr.isEmpty())
488 RTPrintf("Product: %ls\n", bstr.raw());
489 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
490 if (!bstr.isEmpty())
491 RTPrintf("SerialNumber: %ls\n", bstr.raw());
492 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
493 if (!bstr.isEmpty())
494 RTPrintf("Address: %ls\n", bstr.raw());
495
496 /* current state */
497 USBDeviceState_T state;
498 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
499 const char *pszState = "?";
500 switch (state)
501 {
502 case USBDeviceState_NotSupported:
503 pszState = "Not supported";
504 break;
505 case USBDeviceState_Unavailable:
506 pszState = "Unavailable";
507 break;
508 case USBDeviceState_Busy:
509 pszState = "Busy";
510 break;
511 case USBDeviceState_Available:
512 pszState = "Available";
513 break;
514 case USBDeviceState_Held:
515 pszState = "Held";
516 break;
517 case USBDeviceState_Captured:
518 pszState = "Captured";
519 break;
520 default:
521 ASSERT(false);
522 break;
523 }
524 RTPrintf("Current State: %s\n\n", pszState);
525 }
526 }
527 return rc;
528}
529
530
531/**
532 * List USB filters.
533 *
534 * @returns See produceList.
535 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
536 */
537static HRESULT listUsbFilters(const ComPtr<IVirtualBox> &pVirtualBox)
538{
539 HRESULT rc;
540
541 RTPrintf("Global USB Device Filters:\n\n");
542
543 ComPtr<IHost> host;
544 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
545
546 SafeIfaceArray<IHostUSBDeviceFilter> coll;
547 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
548
549 if (coll.size() == 0)
550 {
551 RTPrintf("<none>\n\n");
552 }
553 else
554 {
555 for (size_t index = 0; index < coll.size(); ++index)
556 {
557 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
558
559 /* Query info. */
560
561 RTPrintf("Index: %zu\n", index);
562
563 BOOL active = FALSE;
564 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
565 RTPrintf("Active: %s\n", active ? "yes" : "no");
566
567 USBDeviceFilterAction_T action;
568 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
569 const char *pszAction = "<invalid>";
570 switch (action)
571 {
572 case USBDeviceFilterAction_Ignore:
573 pszAction = "Ignore";
574 break;
575 case USBDeviceFilterAction_Hold:
576 pszAction = "Hold";
577 break;
578 default:
579 break;
580 }
581 RTPrintf("Action: %s\n", pszAction);
582
583 Bstr bstr;
584 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
585 RTPrintf("Name: %ls\n", bstr.raw());
586 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
587 RTPrintf("VendorId: %ls\n", bstr.raw());
588 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
589 RTPrintf("ProductId: %ls\n", bstr.raw());
590 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
591 RTPrintf("Revision: %ls\n", bstr.raw());
592 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
593 RTPrintf("Manufacturer: %ls\n", bstr.raw());
594 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
595 RTPrintf("Product: %ls\n", bstr.raw());
596 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
597 RTPrintf("Serial Number: %ls\n\n", bstr.raw());
598 }
599 }
600 return rc;
601}
602
603
604/**
605 * List system properties.
606 *
607 * @returns See produceList.
608 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
609 */
610static HRESULT listSystemProperties(const ComPtr<IVirtualBox> &pVirtualBox)
611{
612 ComPtr<ISystemProperties> systemProperties;
613 pVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
614
615 Bstr str;
616 ULONG ulValue;
617 LONG64 i64Value;
618 BOOL fValue;
619 const char *psz;
620
621 pVirtualBox->COMGETTER(APIVersion)(str.asOutParam());
622 RTPrintf("API version: %ls\n", str.raw());
623
624 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
625 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
626 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
627 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
628 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
629 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
630 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
631 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
632 systemProperties->COMGETTER(MaxGuestMonitors)(&ulValue);
633 RTPrintf("Maximum guest monitor count: %u\n", ulValue);
634 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
635 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
636 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
637 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
638 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
639 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
640 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
641 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
642 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
643 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
644 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
645 RTPrintf("Maximum Boot Position: %u\n", ulValue);
646 systemProperties->GetMaxNetworkAdapters(ChipsetType_PIIX3, &ulValue);
647 RTPrintf("Maximum PIIX3 Network Adapter count: %u\n", ulValue);
648 systemProperties->GetMaxNetworkAdapters(ChipsetType_ICH9, &ulValue);
649 RTPrintf("Maximum ICH9 Network Adapter count: %u\n", ulValue);
650 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
651 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
652 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
653 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
654 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
655 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
656 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
657 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
658 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
659 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
660 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
661 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
662 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
663 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
664 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
665 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
666 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
667 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
668 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
669 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
670 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
671 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
672 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
673 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
674 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
675 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
676 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
677 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
678 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
679 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
680 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
681 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
682 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_PCIe, &ulValue);
683 RTPrintf("Maximum NVMe PIIX3 Controllers: %u\n", ulValue);
684 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_PCIe, &ulValue);
685 RTPrintf("Maximum NVMe ICH9 Controllers: %u\n", ulValue);
686 systemProperties->GetMaxPortCountForStorageBus(StorageBus_PCIe, &ulValue);
687 RTPrintf("Maximum NVMe Port count: %u\n", ulValue);
688 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_PCIe, &ulValue);
689 RTPrintf("Maximum Devices per NVMe Port: %u\n", ulValue);
690 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
691 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
692 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
693 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
694 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
695 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
696 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
697 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
698#if 0
699 systemProperties->GetFreeDiskSpaceWarning(&i64Value);
700 RTPrintf("Free disk space warning at: %u Bytes\n", i64Value);
701 systemProperties->GetFreeDiskSpacePercentWarning(&ulValue);
702 RTPrintf("Free disk space warning at: %u %%\n", ulValue);
703 systemProperties->GetFreeDiskSpaceError(&i64Value);
704 RTPrintf("Free disk space error at: %u Bytes\n", i64Value);
705 systemProperties->GetFreeDiskSpacePercentError(&ulValue);
706 RTPrintf("Free disk space error at: %u %%\n", ulValue);
707#endif
708 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
709 RTPrintf("Default machine folder: %ls\n", str.raw());
710 systemProperties->COMGETTER(RawModeSupported)(&fValue);
711 RTPrintf("Raw-mode Supported: %s\n", fValue ? "yes" : "no");
712 systemProperties->COMGETTER(ExclusiveHwVirt)(&fValue);
713 RTPrintf("Exclusive HW virtualization use: %s\n", fValue ? "on" : "off");
714 systemProperties->COMGETTER(DefaultHardDiskFormat)(str.asOutParam());
715 RTPrintf("Default hard disk format: %ls\n", str.raw());
716 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
717 RTPrintf("VRDE auth library: %ls\n", str.raw());
718 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
719 RTPrintf("Webservice auth. library: %ls\n", str.raw());
720 systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
721 RTPrintf("Remote desktop ExtPack: %ls\n", str.raw());
722 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
723 RTPrintf("Log history count: %u\n", ulValue);
724 systemProperties->COMGETTER(DefaultFrontend)(str.asOutParam());
725 RTPrintf("Default frontend: %ls\n", str.raw());
726 AudioDriverType_T enmAudio;
727 systemProperties->COMGETTER(DefaultAudioDriver)(&enmAudio);
728 switch (enmAudio)
729 {
730 case AudioDriverType_Null: psz = "Null"; break;
731 case AudioDriverType_WinMM: psz = "WinMM"; break;
732 case AudioDriverType_OSS: psz = "OSS"; break;
733 case AudioDriverType_ALSA: psz = "ALSA"; break;
734 case AudioDriverType_DirectSound: psz = "DirectSound"; break;
735 case AudioDriverType_CoreAudio: psz = "CoreAudio"; break;
736 case AudioDriverType_MMPM: psz = "MMPM"; break;
737 case AudioDriverType_Pulse: psz = "Pulse"; break;
738 case AudioDriverType_SolAudio: psz = "SolAudio"; break;
739 default: psz = "Unknown";
740 }
741 RTPrintf("Default audio driver: %s\n", psz);
742 systemProperties->COMGETTER(AutostartDatabasePath)(str.asOutParam());
743 RTPrintf("Autostart database path: %ls\n", str.raw());
744 systemProperties->COMGETTER(DefaultAdditionsISO)(str.asOutParam());
745 RTPrintf("Default Guest Additions ISO: %ls\n", str.raw());
746 systemProperties->COMGETTER(LoggingLevel)(str.asOutParam());
747 RTPrintf("Logging Level: %ls\n", str.raw());
748 return S_OK;
749}
750
751
752/**
753 * List extension packs.
754 *
755 * @returns See produceList.
756 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
757 */
758static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
759{
760 ComObjPtr<IExtPackManager> ptrExtPackMgr;
761 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
762
763 SafeIfaceArray<IExtPack> extPacks;
764 CHECK_ERROR2I_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
765 RTPrintf("Extension Packs: %u\n", extPacks.size());
766
767 HRESULT hrc = S_OK;
768 for (size_t i = 0; i < extPacks.size(); i++)
769 {
770 /* Read all the properties. */
771 Bstr bstrName;
772 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
773 Bstr bstrDesc;
774 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
775 Bstr bstrVersion;
776 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
777 ULONG uRevision;
778 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
779 Bstr bstrEdition;
780 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
781 Bstr bstrVrdeModule;
782 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
783 BOOL fUsable;
784 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
785 Bstr bstrWhy;
786 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
787
788 /* Display them. */
789 if (i)
790 RTPrintf("\n");
791 RTPrintf("Pack no.%2zu: %ls\n"
792 "Version: %ls\n"
793 "Revision: %u\n"
794 "Edition: %ls\n"
795 "Description: %ls\n"
796 "VRDE Module: %ls\n"
797 "Usable: %RTbool\n"
798 "Why unusable: %ls\n",
799 i, bstrName.raw(),
800 bstrVersion.raw(),
801 uRevision,
802 bstrEdition.raw(),
803 bstrDesc.raw(),
804 bstrVrdeModule.raw(),
805 fUsable != FALSE,
806 bstrWhy.raw());
807
808 /* Query plugins and display them. */
809 }
810 return hrc;
811}
812
813
814/**
815 * List machine groups.
816 *
817 * @returns See produceList.
818 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
819 */
820static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
821{
822 SafeArray<BSTR> groups;
823 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
824
825 for (size_t i = 0; i < groups.size(); i++)
826 {
827 RTPrintf("\"%ls\"\n", groups[i]);
828 }
829 return S_OK;
830}
831
832
833/**
834 * List video capture devices.
835 *
836 * @returns See produceList.
837 * @param pVirtualBox Reference to the IVirtualBox pointer.
838 */
839static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> pVirtualBox)
840{
841 HRESULT rc;
842 ComPtr<IHost> host;
843 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
844 com::SafeIfaceArray<IHostVideoInputDevice> hostVideoInputDevices;
845 CHECK_ERROR(host, COMGETTER(VideoInputDevices)(ComSafeArrayAsOutParam(hostVideoInputDevices)));
846 RTPrintf("Video Input Devices: %u\n", hostVideoInputDevices.size());
847 for (size_t i = 0; i < hostVideoInputDevices.size(); ++i)
848 {
849 ComPtr<IHostVideoInputDevice> p = hostVideoInputDevices[i];
850 Bstr name;
851 p->COMGETTER(Name)(name.asOutParam());
852 Bstr path;
853 p->COMGETTER(Path)(path.asOutParam());
854 Bstr alias;
855 p->COMGETTER(Alias)(alias.asOutParam());
856 RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
857 }
858 return rc;
859}
860
861/**
862 * List supported screen shot formats.
863 *
864 * @returns See produceList.
865 * @param pVirtualBox Reference to the IVirtualBox pointer.
866 */
867static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> pVirtualBox)
868{
869 HRESULT rc = S_OK;
870 ComPtr<ISystemProperties> systemProperties;
871 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
872 com::SafeArray<BitmapFormat_T> formats;
873 CHECK_ERROR(systemProperties, COMGETTER(ScreenShotFormats)(ComSafeArrayAsOutParam(formats)));
874
875 RTPrintf("Supported %d screen shot formats:\n", formats.size());
876 for (size_t i = 0; i < formats.size(); ++i)
877 {
878 uint32_t u32Format = (uint32_t)formats[i];
879 char szFormat[5];
880 szFormat[0] = RT_BYTE1(u32Format);
881 szFormat[1] = RT_BYTE2(u32Format);
882 szFormat[2] = RT_BYTE3(u32Format);
883 szFormat[3] = RT_BYTE4(u32Format);
884 szFormat[4] = 0;
885 RTPrintf(" BitmapFormat_%s (0x%08X)\n", szFormat, u32Format);
886 }
887 return rc;
888}
889
890
891/**
892 * The type of lists we can produce.
893 */
894enum enmListType
895{
896 kListNotSpecified = 1000,
897 kListVMs,
898 kListRunningVMs,
899 kListOsTypes,
900 kListHostDvds,
901 kListHostFloppies,
902 kListInternalNetworks,
903 kListBridgedInterfaces,
904#if defined(VBOX_WITH_NETFLT)
905 kListHostOnlyInterfaces,
906#endif
907 kListHostCpuIDs,
908 kListHostInfo,
909 kListHddBackends,
910 kListHdds,
911 kListDvds,
912 kListFloppies,
913 kListUsbHost,
914 kListUsbFilters,
915 kListSystemProperties,
916 kListDhcpServers,
917 kListExtPacks,
918 kListGroups,
919 kListNatNetworks,
920 kListVideoInputDevices,
921 kListScreenShotFormats
922};
923
924
925/**
926 * Produces the specified listing.
927 *
928 * @returns S_OK or some COM error code that has been reported in full.
929 * @param enmList The list to produce.
930 * @param fOptLong Long (@c true) or short list format.
931 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
932 */
933static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
934{
935 HRESULT rc = S_OK;
936 switch (enmCommand)
937 {
938 case kListNotSpecified:
939 AssertFailed();
940 return E_FAIL;
941
942 case kListVMs:
943 {
944 /*
945 * Get the list of all registered VMs
946 */
947 com::SafeIfaceArray<IMachine> machines;
948 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
949 if (SUCCEEDED(rc))
950 {
951 /*
952 * Display it.
953 */
954 if (!fOptSorted)
955 {
956 for (size_t i = 0; i < machines.size(); ++i)
957 if (machines[i])
958 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
959 }
960 else
961 {
962 /*
963 * Sort the list by name before displaying it.
964 */
965 std::vector<std::pair<com::Bstr, IMachine *> > sortedMachines;
966 for (size_t i = 0; i < machines.size(); ++i)
967 {
968 IMachine *pMachine = machines[i];
969 if (pMachine) /* no idea why we need to do this... */
970 {
971 Bstr bstrName;
972 pMachine->COMGETTER(Name)(bstrName.asOutParam());
973 sortedMachines.push_back(std::pair<com::Bstr, IMachine *>(bstrName, pMachine));
974 }
975 }
976
977 std::sort(sortedMachines.begin(), sortedMachines.end());
978
979 for (size_t i = 0; i < sortedMachines.size(); ++i)
980 rc = showVMInfo(pVirtualBox, sortedMachines[i].second, NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
981 }
982 }
983 break;
984 }
985
986 case kListRunningVMs:
987 {
988 /*
989 * Get the list of all _running_ VMs
990 */
991 com::SafeIfaceArray<IMachine> machines;
992 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
993 com::SafeArray<MachineState_T> states;
994 if (SUCCEEDED(rc))
995 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
996 if (SUCCEEDED(rc))
997 {
998 /*
999 * Iterate through the collection
1000 */
1001 for (size_t i = 0; i < machines.size(); ++i)
1002 {
1003 if (machines[i])
1004 {
1005 MachineState_T machineState = states[i];
1006 switch (machineState)
1007 {
1008 case MachineState_Running:
1009 case MachineState_Teleporting:
1010 case MachineState_LiveSnapshotting:
1011 case MachineState_Paused:
1012 case MachineState_TeleportingPausedVM:
1013 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1014 break;
1015 default: break; /* Shut up MSC */
1016 }
1017 }
1018 }
1019 }
1020 break;
1021 }
1022
1023 case kListOsTypes:
1024 {
1025 com::SafeIfaceArray<IGuestOSType> coll;
1026 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
1027 if (SUCCEEDED(rc))
1028 {
1029 /*
1030 * Iterate through the collection.
1031 */
1032 for (size_t i = 0; i < coll.size(); ++i)
1033 {
1034 ComPtr<IGuestOSType> guestOS;
1035 guestOS = coll[i];
1036 Bstr guestId;
1037 guestOS->COMGETTER(Id)(guestId.asOutParam());
1038 RTPrintf("ID: %ls\n", guestId.raw());
1039 Bstr guestDescription;
1040 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
1041 RTPrintf("Description: %ls\n", guestDescription.raw());
1042 Bstr familyId;
1043 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
1044 RTPrintf("Family ID: %ls\n", familyId.raw());
1045 Bstr familyDescription;
1046 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
1047 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
1048 BOOL is64Bit;
1049 guestOS->COMGETTER(Is64Bit)(&is64Bit);
1050 RTPrintf("64 bit: %RTbool\n", is64Bit);
1051 RTPrintf("\n");
1052 }
1053 }
1054 break;
1055 }
1056
1057 case kListHostDvds:
1058 {
1059 ComPtr<IHost> host;
1060 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1061 com::SafeIfaceArray<IMedium> coll;
1062 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
1063 if (SUCCEEDED(rc))
1064 {
1065 for (size_t i = 0; i < coll.size(); ++i)
1066 {
1067 ComPtr<IMedium> dvdDrive = coll[i];
1068 Bstr uuid;
1069 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
1070 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1071 Bstr location;
1072 dvdDrive->COMGETTER(Location)(location.asOutParam());
1073 RTPrintf("Name: %ls\n\n", location.raw());
1074 }
1075 }
1076 break;
1077 }
1078
1079 case kListHostFloppies:
1080 {
1081 ComPtr<IHost> host;
1082 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1083 com::SafeIfaceArray<IMedium> coll;
1084 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
1085 if (SUCCEEDED(rc))
1086 {
1087 for (size_t i = 0; i < coll.size(); ++i)
1088 {
1089 ComPtr<IMedium> floppyDrive = coll[i];
1090 Bstr uuid;
1091 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1092 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1093 Bstr location;
1094 floppyDrive->COMGETTER(Location)(location.asOutParam());
1095 RTPrintf("Name: %ls\n\n", location.raw());
1096 }
1097 }
1098 break;
1099 }
1100
1101 case kListInternalNetworks:
1102 rc = listInternalNetworks(pVirtualBox);
1103 break;
1104
1105 case kListBridgedInterfaces:
1106#if defined(VBOX_WITH_NETFLT)
1107 case kListHostOnlyInterfaces:
1108#endif
1109 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1110 break;
1111
1112 case kListHostInfo:
1113 rc = listHostInfo(pVirtualBox);
1114 break;
1115
1116 case kListHostCpuIDs:
1117 {
1118 ComPtr<IHost> Host;
1119 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
1120
1121 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
1122 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
1123 static uint32_t const s_auCpuIdRanges[] =
1124 {
1125 UINT32_C(0x00000000), UINT32_C(0x0000007f),
1126 UINT32_C(0x80000000), UINT32_C(0x8000007f),
1127 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
1128 };
1129 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
1130 {
1131 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
1132 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
1133 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
1134 continue;
1135 cLeafs++;
1136 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
1137 {
1138 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
1139 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
1140 }
1141 }
1142 break;
1143 }
1144
1145 case kListHddBackends:
1146 rc = listHddBackends(pVirtualBox);
1147 break;
1148
1149 case kListHdds:
1150 {
1151 com::SafeIfaceArray<IMedium> hdds;
1152 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
1153 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
1154 break;
1155 }
1156
1157 case kListDvds:
1158 {
1159 com::SafeIfaceArray<IMedium> dvds;
1160 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
1161 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
1162 break;
1163 }
1164
1165 case kListFloppies:
1166 {
1167 com::SafeIfaceArray<IMedium> floppies;
1168 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
1169 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
1170 break;
1171 }
1172
1173 case kListUsbHost:
1174 rc = listUsbHost(pVirtualBox);
1175 break;
1176
1177 case kListUsbFilters:
1178 rc = listUsbFilters(pVirtualBox);
1179 break;
1180
1181 case kListSystemProperties:
1182 rc = listSystemProperties(pVirtualBox);
1183 break;
1184
1185 case kListDhcpServers:
1186 {
1187 com::SafeIfaceArray<IDHCPServer> svrs;
1188 CHECK_ERROR(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
1189 for (size_t i = 0; i < svrs.size(); ++i)
1190 {
1191 ComPtr<IDHCPServer> svr = svrs[i];
1192 Bstr netName;
1193 svr->COMGETTER(NetworkName)(netName.asOutParam());
1194 RTPrintf("NetworkName: %ls\n", netName.raw());
1195 Bstr ip;
1196 svr->COMGETTER(IPAddress)(ip.asOutParam());
1197 RTPrintf("IP: %ls\n", ip.raw());
1198 Bstr netmask;
1199 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
1200 RTPrintf("NetworkMask: %ls\n", netmask.raw());
1201 Bstr lowerIp;
1202 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
1203 RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw());
1204 Bstr upperIp;
1205 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
1206 RTPrintf("upperIPAddress: %ls\n", upperIp.raw());
1207 BOOL fEnabled;
1208 svr->COMGETTER(Enabled)(&fEnabled);
1209 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1210 RTPrintf("\n");
1211 }
1212 break;
1213 }
1214
1215 case kListExtPacks:
1216 rc = listExtensionPacks(pVirtualBox);
1217 break;
1218
1219 case kListGroups:
1220 rc = listGroups(pVirtualBox);
1221 break;
1222
1223 case kListNatNetworks:
1224 {
1225 com::SafeIfaceArray<INATNetwork> nets;
1226 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
1227 for (size_t i = 0; i < nets.size(); ++i)
1228 {
1229 ComPtr<INATNetwork> net = nets[i];
1230 Bstr netName;
1231 net->COMGETTER(NetworkName)(netName.asOutParam());
1232 RTPrintf("NetworkName: %ls\n", netName.raw());
1233 Bstr gateway;
1234 net->COMGETTER(Gateway)(gateway.asOutParam());
1235 RTPrintf("IP: %ls\n", gateway.raw());
1236 Bstr network;
1237 net->COMGETTER(Network)(network.asOutParam());
1238 RTPrintf("Network: %ls\n", network.raw());
1239 BOOL fEnabled;
1240 net->COMGETTER(IPv6Enabled)(&fEnabled);
1241 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
1242 Bstr ipv6prefix;
1243 net->COMGETTER(IPv6Prefix)(ipv6prefix.asOutParam());
1244 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
1245 net->COMGETTER(NeedDhcpServer)(&fEnabled);
1246 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
1247 net->COMGETTER(Enabled)(&fEnabled);
1248 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1249
1250#define PRINT_STRING_ARRAY(title) \
1251 if (strs.size() > 0) \
1252 { \
1253 RTPrintf(title); \
1254 size_t j = 0; \
1255 for (;j < strs.size(); ++j) \
1256 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
1257 }
1258
1259 com::SafeArray<BSTR> strs;
1260
1261 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
1262 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
1263 strs.setNull();
1264
1265 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
1266 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
1267 strs.setNull();
1268
1269 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
1270 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
1271 strs.setNull();
1272
1273#undef PRINT_STRING_ARRAY
1274 RTPrintf("\n");
1275 }
1276 break;
1277 }
1278
1279 case kListVideoInputDevices:
1280 rc = listVideoInputDevices(pVirtualBox);
1281 break;
1282
1283 case kListScreenShotFormats:
1284 rc = listScreenShotFormats(pVirtualBox);
1285 break;
1286
1287 /* No default here, want gcc warnings. */
1288
1289 } /* end switch */
1290
1291 return rc;
1292}
1293
1294/**
1295 * Handles the 'list' command.
1296 *
1297 * @returns Appropriate exit code.
1298 * @param a Handler argument.
1299 */
1300RTEXITCODE handleList(HandlerArg *a)
1301{
1302 bool fOptLong = false;
1303 bool fOptMultiple = false;
1304 bool fOptSorted = false;
1305 enum enmListType enmOptCommand = kListNotSpecified;
1306
1307 static const RTGETOPTDEF s_aListOptions[] =
1308 {
1309 { "--long", 'l', RTGETOPT_REQ_NOTHING },
1310 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
1311 { "--sorted", 's', RTGETOPT_REQ_NOTHING },
1312 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
1313 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
1314 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
1315 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
1316 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
1317 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
1318 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
1319 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
1320#if defined(VBOX_WITH_NETFLT)
1321 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
1322#endif
1323 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1324 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1325 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
1326 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
1327 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
1328 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
1329 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
1330 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
1331 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
1332 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
1333 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
1334 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
1335 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
1336 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
1337 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
1338 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
1339 };
1340
1341 int ch;
1342 RTGETOPTUNION ValueUnion;
1343 RTGETOPTSTATE GetState;
1344 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
1345 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1346 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1347 {
1348 switch (ch)
1349 {
1350 case 'l': /* --long */
1351 fOptLong = true;
1352 break;
1353
1354 case 's':
1355 fOptSorted = true;
1356 break;
1357
1358 case 'm':
1359 fOptMultiple = true;
1360 if (enmOptCommand == kListNotSpecified)
1361 break;
1362 ch = enmOptCommand;
1363 RT_FALL_THRU();
1364
1365 case kListVMs:
1366 case kListRunningVMs:
1367 case kListOsTypes:
1368 case kListHostDvds:
1369 case kListHostFloppies:
1370 case kListInternalNetworks:
1371 case kListBridgedInterfaces:
1372#if defined(VBOX_WITH_NETFLT)
1373 case kListHostOnlyInterfaces:
1374#endif
1375 case kListHostInfo:
1376 case kListHostCpuIDs:
1377 case kListHddBackends:
1378 case kListHdds:
1379 case kListDvds:
1380 case kListFloppies:
1381 case kListUsbHost:
1382 case kListUsbFilters:
1383 case kListSystemProperties:
1384 case kListDhcpServers:
1385 case kListExtPacks:
1386 case kListGroups:
1387 case kListNatNetworks:
1388 case kListVideoInputDevices:
1389 case kListScreenShotFormats:
1390 enmOptCommand = (enum enmListType)ch;
1391 if (fOptMultiple)
1392 {
1393 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, fOptSorted, a->virtualBox);
1394 if (FAILED(hrc))
1395 return RTEXITCODE_FAILURE;
1396 }
1397 break;
1398
1399 case VINF_GETOPT_NOT_OPTION:
1400 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1401
1402 default:
1403 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1404 }
1405 }
1406
1407 /*
1408 * If not in multiple list mode, we have to produce the list now.
1409 */
1410 if (enmOptCommand == kListNotSpecified)
1411 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1412 if (!fOptMultiple)
1413 {
1414 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
1415 if (FAILED(hrc))
1416 return RTEXITCODE_FAILURE;
1417 }
1418
1419 return RTEXITCODE_SUCCESS;
1420}
1421
1422#endif /* !VBOX_ONLY_DOCS */
1423/* 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