VirtualBox

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

Last change on this file since 61577 was 61577, checked in by vboxsync, 9 years ago

Frontends/VBoxManage: show default audio driver when listing system properties

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