VirtualBox

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

Last change on this file since 48607 was 48607, checked in by vboxsync, 11 years ago

VBoxManage,Main: VideoCaptureDevice -> VideoInputDevice

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