VirtualBox

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

Last change on this file since 52989 was 52200, checked in by vboxsync, 10 years ago

Main,Frontends: TakeScreenShot API cleanup.

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