VirtualBox

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

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

build fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.3 KB
Line 
1/* $Id: VBoxManageList.cpp 60685 2016-04-25 12:09:49Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2015 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
605 pVirtualBox->COMGETTER(APIVersion)(str.asOutParam());
606 RTPrintf("API version: %ls\n", str.raw());
607
608 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
609 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
610 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
611 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
612 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
613 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
614 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
615 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
616 systemProperties->COMGETTER(MaxGuestMonitors)(&ulValue);
617 RTPrintf("Maximum guest monitor count: %u\n", ulValue);
618 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
619 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
620 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
621 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
622 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
623 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
624 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
625 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
626 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
627 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
628 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
629 RTPrintf("Maximum Boot Position: %u\n", ulValue);
630 systemProperties->GetMaxNetworkAdapters(ChipsetType_PIIX3, &ulValue);
631 RTPrintf("Maximum PIIX3 Network Adapter count: %u\n", ulValue);
632 systemProperties->GetMaxNetworkAdapters(ChipsetType_ICH9, &ulValue);
633 RTPrintf("Maximum ICH9 Network Adapter count: %u\n", ulValue);
634 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
635 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
636 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
637 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
638 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
639 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
640 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
641 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
642 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
643 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
644 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
645 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
646 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
647 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
648 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
649 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
650 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
651 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
652 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
653 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
654 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
655 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
656 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
657 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
658 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
659 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
660 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
661 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
662 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
663 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
664 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
665 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
666 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
667 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
668 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
669 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
670 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
671 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
672 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
673 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
674#if 0
675 systemProperties->GetFreeDiskSpaceWarning(&i64Value);
676 RTPrintf("Free disk space warning at: %u Bytes\n", i64Value);
677 systemProperties->GetFreeDiskSpacePercentWarning(&ulValue);
678 RTPrintf("Free disk space warning at: %u %%\n", ulValue);
679 systemProperties->GetFreeDiskSpaceError(&i64Value);
680 RTPrintf("Free disk space error at: %u Bytes\n", i64Value);
681 systemProperties->GetFreeDiskSpacePercentError(&ulValue);
682 RTPrintf("Free disk space error at: %u %%\n", ulValue);
683#endif
684 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
685 RTPrintf("Default machine folder: %ls\n", str.raw());
686 systemProperties->COMGETTER(RawModeSupported)(&fValue);
687 RTPrintf("Raw-mode Supported: %s\n", fValue ? "yes" : "no");
688 systemProperties->COMGETTER(ExclusiveHwVirt)(&fValue);
689 RTPrintf("Exclusive HW virtualization use: %s\n", fValue ? "on" : "off");
690 systemProperties->COMGETTER(DefaultHardDiskFormat)(str.asOutParam());
691 RTPrintf("Default hard disk format: %ls\n", str.raw());
692 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
693 RTPrintf("VRDE auth library: %ls\n", str.raw());
694 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
695 RTPrintf("Webservice auth. library: %ls\n", str.raw());
696 systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
697 RTPrintf("Remote desktop ExtPack: %ls\n", str.raw());
698 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
699 RTPrintf("Log history count: %u\n", ulValue);
700 systemProperties->COMGETTER(DefaultFrontend)(str.asOutParam());
701 RTPrintf("Default frontend: %ls\n", str.raw());
702 systemProperties->COMGETTER(AutostartDatabasePath)(str.asOutParam());
703 RTPrintf("Autostart database path: %ls\n", str.raw());
704 systemProperties->COMGETTER(DefaultAdditionsISO)(str.asOutParam());
705 RTPrintf("Default Guest Additions ISO: %ls\n", str.raw());
706 systemProperties->COMGETTER(LoggingLevel)(str.asOutParam());
707 RTPrintf("Logging Level: %ls\n", str.raw());
708 return S_OK;
709}
710
711
712/**
713 * List extension packs.
714 *
715 * @returns See produceList.
716 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
717 */
718static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
719{
720 ComObjPtr<IExtPackManager> ptrExtPackMgr;
721 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
722
723 SafeIfaceArray<IExtPack> extPacks;
724 CHECK_ERROR2I_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
725 RTPrintf("Extension Packs: %u\n", extPacks.size());
726
727 HRESULT hrc = S_OK;
728 for (size_t i = 0; i < extPacks.size(); i++)
729 {
730 /* Read all the properties. */
731 Bstr bstrName;
732 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
733 Bstr bstrDesc;
734 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
735 Bstr bstrVersion;
736 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
737 ULONG uRevision;
738 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
739 Bstr bstrEdition;
740 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
741 Bstr bstrVrdeModule;
742 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
743 BOOL fUsable;
744 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
745 Bstr bstrWhy;
746 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
747
748 /* Display them. */
749 if (i)
750 RTPrintf("\n");
751 RTPrintf("Pack no.%2zu: %ls\n"
752 "Version: %ls\n"
753 "Revision: %u\n"
754 "Edition: %ls\n"
755 "Description: %ls\n"
756 "VRDE Module: %ls\n"
757 "Usable: %RTbool\n"
758 "Why unusable: %ls\n",
759 i, bstrName.raw(),
760 bstrVersion.raw(),
761 uRevision,
762 bstrEdition.raw(),
763 bstrDesc.raw(),
764 bstrVrdeModule.raw(),
765 fUsable != FALSE,
766 bstrWhy.raw());
767
768 /* Query plugins and display them. */
769 }
770 return hrc;
771}
772
773
774/**
775 * List machine groups.
776 *
777 * @returns See produceList.
778 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
779 */
780static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
781{
782 SafeArray<BSTR> groups;
783 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
784
785 for (size_t i = 0; i < groups.size(); i++)
786 {
787 RTPrintf("\"%ls\"\n", groups[i]);
788 }
789 return S_OK;
790}
791
792
793/**
794 * List video capture devices.
795 *
796 * @returns See produceList.
797 * @param pVirtualBox Reference to the IVirtualBox pointer.
798 */
799static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> pVirtualBox)
800{
801 HRESULT rc;
802 ComPtr<IHost> host;
803 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
804 com::SafeIfaceArray<IHostVideoInputDevice> hostVideoInputDevices;
805 CHECK_ERROR(host, COMGETTER(VideoInputDevices)(ComSafeArrayAsOutParam(hostVideoInputDevices)));
806 RTPrintf("Video Input Devices: %u\n", hostVideoInputDevices.size());
807 for (size_t i = 0; i < hostVideoInputDevices.size(); ++i)
808 {
809 ComPtr<IHostVideoInputDevice> p = hostVideoInputDevices[i];
810 Bstr name;
811 p->COMGETTER(Name)(name.asOutParam());
812 Bstr path;
813 p->COMGETTER(Path)(path.asOutParam());
814 Bstr alias;
815 p->COMGETTER(Alias)(alias.asOutParam());
816 RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
817 }
818 return rc;
819}
820
821/**
822 * List supported screen shot formats.
823 *
824 * @returns See produceList.
825 * @param pVirtualBox Reference to the IVirtualBox pointer.
826 */
827static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> pVirtualBox)
828{
829 HRESULT rc = S_OK;
830 ComPtr<ISystemProperties> systemProperties;
831 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
832 com::SafeArray<BitmapFormat_T> formats;
833 CHECK_ERROR(systemProperties, COMGETTER(ScreenShotFormats)(ComSafeArrayAsOutParam(formats)));
834
835 RTPrintf("Supported %d screen shot formats:\n", formats.size());
836 for (size_t i = 0; i < formats.size(); ++i)
837 {
838 uint32_t u32Format = (uint32_t)formats[i];
839 char szFormat[5];
840 szFormat[0] = RT_BYTE1(u32Format);
841 szFormat[1] = RT_BYTE2(u32Format);
842 szFormat[2] = RT_BYTE3(u32Format);
843 szFormat[3] = RT_BYTE4(u32Format);
844 szFormat[4] = 0;
845 RTPrintf(" BitmapFormat_%s (0x%08X)\n", szFormat, u32Format);
846 }
847 return rc;
848}
849
850
851/**
852 * The type of lists we can produce.
853 */
854enum enmListType
855{
856 kListNotSpecified = 1000,
857 kListVMs,
858 kListRunningVMs,
859 kListOsTypes,
860 kListHostDvds,
861 kListHostFloppies,
862 kListInternalNetworks,
863 kListBridgedInterfaces,
864#if defined(VBOX_WITH_NETFLT)
865 kListHostOnlyInterfaces,
866#endif
867 kListHostCpuIDs,
868 kListHostInfo,
869 kListHddBackends,
870 kListHdds,
871 kListDvds,
872 kListFloppies,
873 kListUsbHost,
874 kListUsbFilters,
875 kListSystemProperties,
876 kListDhcpServers,
877 kListExtPacks,
878 kListGroups,
879 kListNatNetworks,
880 kListVideoInputDevices,
881 kListScreenShotFormats
882};
883
884
885/**
886 * Produces the specified listing.
887 *
888 * @returns S_OK or some COM error code that has been reported in full.
889 * @param enmList The list to produce.
890 * @param fOptLong Long (@c true) or short list format.
891 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
892 */
893static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &pVirtualBox)
894{
895 HRESULT rc = S_OK;
896 switch (enmCommand)
897 {
898 case kListNotSpecified:
899 AssertFailed();
900 return E_FAIL;
901
902 case kListVMs:
903 {
904 /*
905 * Get the list of all registered VMs
906 */
907 com::SafeIfaceArray<IMachine> machines;
908 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
909 if (SUCCEEDED(rc))
910 {
911 /*
912 * Iterate through the collection
913 */
914 for (size_t i = 0; i < machines.size(); ++i)
915 {
916 if (machines[i])
917 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
918 }
919 }
920 break;
921 }
922
923 case kListRunningVMs:
924 {
925 /*
926 * Get the list of all _running_ VMs
927 */
928 com::SafeIfaceArray<IMachine> machines;
929 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
930 com::SafeArray<MachineState_T> states;
931 if (SUCCEEDED(rc))
932 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
933 if (SUCCEEDED(rc))
934 {
935 /*
936 * Iterate through the collection
937 */
938 for (size_t i = 0; i < machines.size(); ++i)
939 {
940 if (machines[i])
941 {
942 MachineState_T machineState = states[i];
943 switch (machineState)
944 {
945 case MachineState_Running:
946 case MachineState_Teleporting:
947 case MachineState_LiveSnapshotting:
948 case MachineState_Paused:
949 case MachineState_TeleportingPausedVM:
950 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
951 break;
952 }
953 }
954 }
955 }
956 break;
957 }
958
959 case kListOsTypes:
960 {
961 com::SafeIfaceArray<IGuestOSType> coll;
962 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
963 if (SUCCEEDED(rc))
964 {
965 /*
966 * Iterate through the collection.
967 */
968 for (size_t i = 0; i < coll.size(); ++i)
969 {
970 ComPtr<IGuestOSType> guestOS;
971 guestOS = coll[i];
972 Bstr guestId;
973 guestOS->COMGETTER(Id)(guestId.asOutParam());
974 RTPrintf("ID: %ls\n", guestId.raw());
975 Bstr guestDescription;
976 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
977 RTPrintf("Description: %ls\n", guestDescription.raw());
978 Bstr familyId;
979 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
980 RTPrintf("Family ID: %ls\n", familyId.raw());
981 Bstr familyDescription;
982 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
983 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
984 BOOL is64Bit;
985 guestOS->COMGETTER(Is64Bit)(&is64Bit);
986 RTPrintf("64 bit: %RTbool\n", is64Bit);
987 RTPrintf("\n");
988 }
989 }
990 break;
991 }
992
993 case kListHostDvds:
994 {
995 ComPtr<IHost> host;
996 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
997 com::SafeIfaceArray<IMedium> coll;
998 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
999 if (SUCCEEDED(rc))
1000 {
1001 for (size_t i = 0; i < coll.size(); ++i)
1002 {
1003 ComPtr<IMedium> dvdDrive = coll[i];
1004 Bstr uuid;
1005 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
1006 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1007 Bstr location;
1008 dvdDrive->COMGETTER(Location)(location.asOutParam());
1009 RTPrintf("Name: %ls\n\n", location.raw());
1010 }
1011 }
1012 break;
1013 }
1014
1015 case kListHostFloppies:
1016 {
1017 ComPtr<IHost> host;
1018 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1019 com::SafeIfaceArray<IMedium> coll;
1020 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
1021 if (SUCCEEDED(rc))
1022 {
1023 for (size_t i = 0; i < coll.size(); ++i)
1024 {
1025 ComPtr<IMedium> floppyDrive = coll[i];
1026 Bstr uuid;
1027 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1028 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1029 Bstr location;
1030 floppyDrive->COMGETTER(Location)(location.asOutParam());
1031 RTPrintf("Name: %ls\n\n", location.raw());
1032 }
1033 }
1034 break;
1035 }
1036
1037 case kListInternalNetworks:
1038 rc = listInternalNetworks(pVirtualBox);
1039 break;
1040
1041 case kListBridgedInterfaces:
1042#if defined(VBOX_WITH_NETFLT)
1043 case kListHostOnlyInterfaces:
1044#endif
1045 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1046 break;
1047
1048 case kListHostInfo:
1049 rc = listHostInfo(pVirtualBox);
1050 break;
1051
1052 case kListHostCpuIDs:
1053 {
1054 ComPtr<IHost> Host;
1055 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
1056
1057 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
1058 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
1059 static uint32_t const s_auCpuIdRanges[] =
1060 {
1061 UINT32_C(0x00000000), UINT32_C(0x0000007f),
1062 UINT32_C(0x80000000), UINT32_C(0x8000007f),
1063 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
1064 };
1065 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
1066 {
1067 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
1068 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
1069 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
1070 continue;
1071 cLeafs++;
1072 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
1073 {
1074 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
1075 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
1076 }
1077 }
1078 break;
1079 }
1080
1081 case kListHddBackends:
1082 rc = listHddBackends(pVirtualBox);
1083 break;
1084
1085 case kListHdds:
1086 {
1087 com::SafeIfaceArray<IMedium> hdds;
1088 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
1089 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
1090 break;
1091 }
1092
1093 case kListDvds:
1094 {
1095 com::SafeIfaceArray<IMedium> dvds;
1096 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
1097 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
1098 break;
1099 }
1100
1101 case kListFloppies:
1102 {
1103 com::SafeIfaceArray<IMedium> floppies;
1104 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
1105 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
1106 break;
1107 }
1108
1109 case kListUsbHost:
1110 rc = listUsbHost(pVirtualBox);
1111 break;
1112
1113 case kListUsbFilters:
1114 rc = listUsbFilters(pVirtualBox);
1115 break;
1116
1117 case kListSystemProperties:
1118 rc = listSystemProperties(pVirtualBox);
1119 break;
1120
1121 case kListDhcpServers:
1122 {
1123 com::SafeIfaceArray<IDHCPServer> svrs;
1124 CHECK_ERROR(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
1125 for (size_t i = 0; i < svrs.size(); ++i)
1126 {
1127 ComPtr<IDHCPServer> svr = svrs[i];
1128 Bstr netName;
1129 svr->COMGETTER(NetworkName)(netName.asOutParam());
1130 RTPrintf("NetworkName: %ls\n", netName.raw());
1131 Bstr ip;
1132 svr->COMGETTER(IPAddress)(ip.asOutParam());
1133 RTPrintf("IP: %ls\n", ip.raw());
1134 Bstr netmask;
1135 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
1136 RTPrintf("NetworkMask: %ls\n", netmask.raw());
1137 Bstr lowerIp;
1138 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
1139 RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw());
1140 Bstr upperIp;
1141 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
1142 RTPrintf("upperIPAddress: %ls\n", upperIp.raw());
1143 BOOL fEnabled;
1144 svr->COMGETTER(Enabled)(&fEnabled);
1145 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1146 RTPrintf("\n");
1147 }
1148 break;
1149 }
1150
1151 case kListExtPacks:
1152 rc = listExtensionPacks(pVirtualBox);
1153 break;
1154
1155 case kListGroups:
1156 rc = listGroups(pVirtualBox);
1157 break;
1158
1159 case kListNatNetworks:
1160 {
1161 com::SafeIfaceArray<INATNetwork> nets;
1162 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
1163 for (size_t i = 0; i < nets.size(); ++i)
1164 {
1165 ComPtr<INATNetwork> net = nets[i];
1166 Bstr netName;
1167 net->COMGETTER(NetworkName)(netName.asOutParam());
1168 RTPrintf("NetworkName: %ls\n", netName.raw());
1169 Bstr gateway;
1170 net->COMGETTER(Gateway)(gateway.asOutParam());
1171 RTPrintf("IP: %ls\n", gateway.raw());
1172 Bstr network;
1173 net->COMGETTER(Network)(network.asOutParam());
1174 RTPrintf("Network: %ls\n", network.raw());
1175 BOOL fEnabled;
1176 net->COMGETTER(IPv6Enabled)(&fEnabled);
1177 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
1178 Bstr ipv6prefix;
1179 net->COMGETTER(IPv6Prefix)(ipv6prefix.asOutParam());
1180 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
1181 net->COMGETTER(NeedDhcpServer)(&fEnabled);
1182 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
1183 net->COMGETTER(Enabled)(&fEnabled);
1184 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1185
1186#define PRINT_STRING_ARRAY(title) \
1187 if (strs.size() > 0) \
1188 { \
1189 RTPrintf(title); \
1190 size_t j = 0; \
1191 for (;j < strs.size(); ++j) \
1192 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
1193 }
1194
1195 com::SafeArray<BSTR> strs;
1196
1197 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
1198 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
1199 strs.setNull();
1200
1201 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
1202 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
1203 strs.setNull();
1204
1205 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
1206 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
1207 strs.setNull();
1208
1209#undef PRINT_STRING_ARRAY
1210 RTPrintf("\n");
1211 }
1212 break;
1213 }
1214
1215 case kListVideoInputDevices:
1216 rc = listVideoInputDevices(pVirtualBox);
1217 break;
1218
1219 case kListScreenShotFormats:
1220 rc = listScreenShotFormats(pVirtualBox);
1221 break;
1222
1223 /* No default here, want gcc warnings. */
1224
1225 } /* end switch */
1226
1227 return rc;
1228}
1229
1230/**
1231 * Handles the 'list' command.
1232 *
1233 * @returns Appropriate exit code.
1234 * @param a Handler argument.
1235 */
1236RTEXITCODE handleList(HandlerArg *a)
1237{
1238 bool fOptLong = false;
1239 bool fOptMultiple = false;
1240 enum enmListType enmOptCommand = kListNotSpecified;
1241
1242 static const RTGETOPTDEF s_aListOptions[] =
1243 {
1244 { "--long", 'l', RTGETOPT_REQ_NOTHING },
1245 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
1246 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
1247 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
1248 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
1249 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
1250 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
1251 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
1252 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
1253 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
1254#if defined(VBOX_WITH_NETFLT)
1255 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
1256#endif
1257 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1258 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1259 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
1260 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
1261 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
1262 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
1263 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
1264 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
1265 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
1266 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
1267 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
1268 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
1269 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
1270 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
1271 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
1272 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
1273 };
1274
1275 int ch;
1276 RTGETOPTUNION ValueUnion;
1277 RTGETOPTSTATE GetState;
1278 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
1279 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1280 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1281 {
1282 switch (ch)
1283 {
1284 case 'l': /* --long */
1285 fOptLong = true;
1286 break;
1287
1288 case 'm':
1289 fOptMultiple = true;
1290 if (enmOptCommand == kListNotSpecified)
1291 break;
1292 ch = enmOptCommand;
1293 /* fall thru */
1294
1295 case kListVMs:
1296 case kListRunningVMs:
1297 case kListOsTypes:
1298 case kListHostDvds:
1299 case kListHostFloppies:
1300 case kListInternalNetworks:
1301 case kListBridgedInterfaces:
1302#if defined(VBOX_WITH_NETFLT)
1303 case kListHostOnlyInterfaces:
1304#endif
1305 case kListHostInfo:
1306 case kListHostCpuIDs:
1307 case kListHddBackends:
1308 case kListHdds:
1309 case kListDvds:
1310 case kListFloppies:
1311 case kListUsbHost:
1312 case kListUsbFilters:
1313 case kListSystemProperties:
1314 case kListDhcpServers:
1315 case kListExtPacks:
1316 case kListGroups:
1317 case kListNatNetworks:
1318 case kListVideoInputDevices:
1319 case kListScreenShotFormats:
1320 enmOptCommand = (enum enmListType)ch;
1321 if (fOptMultiple)
1322 {
1323 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);
1324 if (FAILED(hrc))
1325 return RTEXITCODE_FAILURE;
1326 }
1327 break;
1328
1329 case VINF_GETOPT_NOT_OPTION:
1330 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1331
1332 default:
1333 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1334 }
1335 }
1336
1337 /*
1338 * If not in multiple list mode, we have to produce the list now.
1339 */
1340 if (enmOptCommand == kListNotSpecified)
1341 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1342 if (!fOptMultiple)
1343 {
1344 HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);
1345 if (FAILED(hrc))
1346 return RTEXITCODE_FAILURE;
1347 }
1348
1349 return RTEXITCODE_SUCCESS;
1350}
1351
1352#endif /* !VBOX_ONLY_DOCS */
1353/* 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