VirtualBox

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

Last change on this file since 53402 was 53297, checked in by vboxsync, 10 years ago

Main: Added API to report actual USB device speed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 51.1 KB
Line 
1/* $Id: VBoxManageList.cpp 53297 2014-11-10 21:57:22Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2014 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 USBConnectionSpeed_T enmSpeed;
405 CHECK_ERROR_RET(dev, COMGETTER(Speed)(&enmSpeed), 1);
406
407 RTPrintf("UUID: %s\n"
408 "VendorId: %#06x (%04X)\n"
409 "ProductId: %#06x (%04X)\n"
410 "Revision: %u.%u (%02u%02u)\n"
411 "Port: %u\n",
412 Utf8Str(id).c_str(),
413 usVendorId, usVendorId, usProductId, usProductId,
414 bcdRevision >> 8, bcdRevision & 0xff,
415 bcdRevision >> 8, bcdRevision & 0xff,
416 usPort);
417
418 const char *pszSpeed = "?";
419 switch (enmSpeed)
420 {
421 case USBConnectionSpeed_Low:
422 pszSpeed = "Low";
423 break;
424 case USBConnectionSpeed_Full:
425 pszSpeed = "Full";
426 break;
427 case USBConnectionSpeed_High:
428 pszSpeed = "High";
429 break;
430 case USBConnectionSpeed_Super:
431 pszSpeed = "Super";
432 break;
433 case USBConnectionSpeed_SuperPlus:
434 pszSpeed = "SuperPlus";
435 break;
436 default:
437 ASSERT(false);
438 break;
439 }
440
441 RTPrintf("USB version/speed: %u/%s\n", usVersion, pszSpeed);
442
443 /* optional stuff. */
444 Bstr bstr;
445 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
446 if (!bstr.isEmpty())
447 RTPrintf("Manufacturer: %ls\n", bstr.raw());
448 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), 1);
449 if (!bstr.isEmpty())
450 RTPrintf("Product: %ls\n", bstr.raw());
451 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
452 if (!bstr.isEmpty())
453 RTPrintf("SerialNumber: %ls\n", bstr.raw());
454 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
455 if (!bstr.isEmpty())
456 RTPrintf("Address: %ls\n", bstr.raw());
457
458 /* current state */
459 USBDeviceState_T state;
460 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
461 const char *pszState = "?";
462 switch (state)
463 {
464 case USBDeviceState_NotSupported:
465 pszState = "Not supported";
466 break;
467 case USBDeviceState_Unavailable:
468 pszState = "Unavailable";
469 break;
470 case USBDeviceState_Busy:
471 pszState = "Busy";
472 break;
473 case USBDeviceState_Available:
474 pszState = "Available";
475 break;
476 case USBDeviceState_Held:
477 pszState = "Held";
478 break;
479 case USBDeviceState_Captured:
480 pszState = "Captured";
481 break;
482 default:
483 ASSERT(false);
484 break;
485 }
486 RTPrintf("Current State: %s\n\n", pszState);
487 }
488 }
489 return rc;
490}
491
492
493/**
494 * List USB filters.
495 *
496 * @returns See produceList.
497 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
498 */
499static HRESULT listUsbFilters(const ComPtr<IVirtualBox> &pVirtualBox)
500{
501 HRESULT rc;
502
503 RTPrintf("Global USB Device Filters:\n\n");
504
505 ComPtr<IHost> host;
506 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
507
508 SafeIfaceArray<IHostUSBDeviceFilter> coll;
509 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
510
511 if (coll.size() == 0)
512 {
513 RTPrintf("<none>\n\n");
514 }
515 else
516 {
517 for (size_t index = 0; index < coll.size(); ++index)
518 {
519 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
520
521 /* Query info. */
522
523 RTPrintf("Index: %zu\n", index);
524
525 BOOL active = FALSE;
526 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
527 RTPrintf("Active: %s\n", active ? "yes" : "no");
528
529 USBDeviceFilterAction_T action;
530 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
531 const char *pszAction = "<invalid>";
532 switch (action)
533 {
534 case USBDeviceFilterAction_Ignore:
535 pszAction = "Ignore";
536 break;
537 case USBDeviceFilterAction_Hold:
538 pszAction = "Hold";
539 break;
540 default:
541 break;
542 }
543 RTPrintf("Action: %s\n", pszAction);
544
545 Bstr bstr;
546 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
547 RTPrintf("Name: %ls\n", bstr.raw());
548 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
549 RTPrintf("VendorId: %ls\n", bstr.raw());
550 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
551 RTPrintf("ProductId: %ls\n", bstr.raw());
552 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
553 RTPrintf("Revision: %ls\n", bstr.raw());
554 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
555 RTPrintf("Manufacturer: %ls\n", bstr.raw());
556 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
557 RTPrintf("Product: %ls\n", bstr.raw());
558 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
559 RTPrintf("Serial Number: %ls\n\n", bstr.raw());
560 }
561 }
562 return rc;
563}
564
565
566/**
567 * List system properties.
568 *
569 * @returns See produceList.
570 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
571 */
572static HRESULT listSystemProperties(const ComPtr<IVirtualBox> &pVirtualBox)
573{
574 ComPtr<ISystemProperties> systemProperties;
575 pVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
576
577 Bstr str;
578 ULONG ulValue;
579 LONG64 i64Value;
580 BOOL fValue;
581
582 pVirtualBox->COMGETTER(APIVersion)(str.asOutParam());
583 RTPrintf("API version: %ls\n", str.raw());
584
585 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
586 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
587 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
588 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
589 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
590 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
591 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
592 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
593 systemProperties->COMGETTER(MaxGuestMonitors)(&ulValue);
594 RTPrintf("Maximum guest monitor count: %u\n", ulValue);
595 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
596 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
597 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
598 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
599 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
600 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
601 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
602 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
603 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
604 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
605 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
606 RTPrintf("Maximum Boot Position: %u\n", ulValue);
607 systemProperties->GetMaxNetworkAdapters(ChipsetType_PIIX3, &ulValue);
608 RTPrintf("Maximum PIIX3 Network Adapter count: %u\n", ulValue);
609 systemProperties->GetMaxNetworkAdapters(ChipsetType_ICH9, &ulValue);
610 RTPrintf("Maximum ICH9 Network Adapter count: %u\n", ulValue);
611 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
612 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
613 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
614 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
615 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
616 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
617 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
618 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
619 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
620 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
621 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
622 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
623 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
624 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
625 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
626 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
627 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
628 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
629 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
630 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
631 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
632 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
633 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
634 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
635 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
636 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
637 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
638 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
639 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
640 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
641 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
642 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
643 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
644 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
645 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
646 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
647 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
648 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
649 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
650 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
651#if 0
652 systemProperties->GetFreeDiskSpaceWarning(&i64Value);
653 RTPrintf("Free disk space warning at: %u Bytes\n", i64Value);
654 systemProperties->GetFreeDiskSpacePercentWarning(&ulValue);
655 RTPrintf("Free disk space warning at: %u %%\n", ulValue);
656 systemProperties->GetFreeDiskSpaceError(&i64Value);
657 RTPrintf("Free disk space error at: %u Bytes\n", i64Value);
658 systemProperties->GetFreeDiskSpacePercentError(&ulValue);
659 RTPrintf("Free disk space error at: %u %%\n", ulValue);
660#endif
661 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
662 RTPrintf("Default machine folder: %ls\n", str.raw());
663 systemProperties->COMGETTER(ExclusiveHwVirt)(&fValue);
664 RTPrintf("Exclusive HW virtualization use: %ls\n", fValue ? L"on" : L"off");
665 systemProperties->COMGETTER(DefaultHardDiskFormat)(str.asOutParam());
666 RTPrintf("Default hard disk format: %ls\n", str.raw());
667 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
668 RTPrintf("VRDE auth library: %ls\n", str.raw());
669 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
670 RTPrintf("Webservice auth. library: %ls\n", str.raw());
671 systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
672 RTPrintf("Remote desktop ExtPack: %ls\n", str.raw());
673 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
674 RTPrintf("Log history count: %u\n", ulValue);
675 systemProperties->COMGETTER(DefaultFrontend)(str.asOutParam());
676 RTPrintf("Default frontend: %ls\n", str.raw());
677 systemProperties->COMGETTER(AutostartDatabasePath)(str.asOutParam());
678 RTPrintf("Autostart database path: %ls\n", str.raw());
679 systemProperties->COMGETTER(DefaultAdditionsISO)(str.asOutParam());
680 RTPrintf("Default Guest Additions ISO: %ls\n", str.raw());
681 return S_OK;
682}
683
684
685/**
686 * List extension packs.
687 *
688 * @returns See produceList.
689 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
690 */
691static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
692{
693 ComObjPtr<IExtPackManager> ptrExtPackMgr;
694 CHECK_ERROR2_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
695
696 SafeIfaceArray<IExtPack> extPacks;
697 CHECK_ERROR2_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
698 RTPrintf("Extension Packs: %u\n", extPacks.size());
699
700 HRESULT hrc = S_OK;
701 for (size_t i = 0; i < extPacks.size(); i++)
702 {
703 /* Read all the properties. */
704 Bstr bstrName;
705 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
706 Bstr bstrDesc;
707 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
708 Bstr bstrVersion;
709 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
710 ULONG uRevision;
711 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
712 Bstr bstrEdition;
713 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
714 Bstr bstrVrdeModule;
715 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
716 BOOL fUsable;
717 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
718 Bstr bstrWhy;
719 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
720
721 /* Display them. */
722 if (i)
723 RTPrintf("\n");
724 RTPrintf("Pack no.%2zu: %ls\n"
725 "Version: %ls\n"
726 "Revision: %u\n"
727 "Edition: %ls\n"
728 "Description: %ls\n"
729 "VRDE Module: %ls\n"
730 "Usable: %RTbool\n"
731 "Why unusable: %ls\n",
732 i, bstrName.raw(),
733 bstrVersion.raw(),
734 uRevision,
735 bstrEdition.raw(),
736 bstrDesc.raw(),
737 bstrVrdeModule.raw(),
738 fUsable != FALSE,
739 bstrWhy.raw());
740
741 /* Query plugins and display them. */
742 }
743 return hrc;
744}
745
746
747/**
748 * List machine groups.
749 *
750 * @returns See produceList.
751 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
752 */
753static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
754{
755 SafeArray<BSTR> groups;
756 CHECK_ERROR2_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
757
758 for (size_t i = 0; i < groups.size(); i++)
759 {
760 RTPrintf("\"%ls\"\n", groups[i]);
761 }
762 return S_OK;
763}
764
765
766/**
767 * List video capture devices.
768 *
769 * @returns See produceList.
770 * @param pVirtualBox Reference to the IVirtualBox pointer.
771 */
772static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> pVirtualBox)
773{
774 HRESULT rc;
775 ComPtr<IHost> host;
776 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
777 com::SafeIfaceArray<IHostVideoInputDevice> hostVideoInputDevices;
778 CHECK_ERROR(host, COMGETTER(VideoInputDevices)(ComSafeArrayAsOutParam(hostVideoInputDevices)));
779 RTPrintf("Video Input Devices: %u\n", hostVideoInputDevices.size());
780 for (size_t i = 0; i < hostVideoInputDevices.size(); ++i)
781 {
782 ComPtr<IHostVideoInputDevice> p = hostVideoInputDevices[i];
783 Bstr name;
784 p->COMGETTER(Name)(name.asOutParam());
785 Bstr path;
786 p->COMGETTER(Path)(path.asOutParam());
787 Bstr alias;
788 p->COMGETTER(Alias)(alias.asOutParam());
789 RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
790 }
791 return rc;
792}
793
794/**
795 * List supported screen shot formats.
796 *
797 * @returns See produceList.
798 * @param pVirtualBox Reference to the IVirtualBox pointer.
799 */
800static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> pVirtualBox)
801{
802 HRESULT rc = S_OK;
803 ComPtr<ISystemProperties> systemProperties;
804 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
805 com::SafeArray<BitmapFormat_T> formats;
806 CHECK_ERROR(systemProperties, COMGETTER(ScreenShotFormats)(ComSafeArrayAsOutParam(formats)));
807
808 RTPrintf("Supported %d screen shot formats:\n", formats.size());
809 for (size_t i = 0; i < formats.size(); ++i)
810 {
811 uint32_t u32Format = (uint32_t)formats[i];
812 char szFormat[5];
813 szFormat[0] = RT_BYTE1(u32Format);
814 szFormat[1] = RT_BYTE2(u32Format);
815 szFormat[2] = RT_BYTE3(u32Format);
816 szFormat[3] = RT_BYTE4(u32Format);
817 szFormat[4] = 0;
818 RTPrintf(" BitmapFormat_%s (0x%08X)\n", szFormat, u32Format);
819 }
820 return rc;
821}
822
823
824/**
825 * The type of lists we can produce.
826 */
827enum enmListType
828{
829 kListNotSpecified = 1000,
830 kListVMs,
831 kListRunningVMs,
832 kListOsTypes,
833 kListHostDvds,
834 kListHostFloppies,
835 kListInternalNetworks,
836 kListBridgedInterfaces,
837#if defined(VBOX_WITH_NETFLT)
838 kListHostOnlyInterfaces,
839#endif
840 kListHostCpuIDs,
841 kListHostInfo,
842 kListHddBackends,
843 kListHdds,
844 kListDvds,
845 kListFloppies,
846 kListUsbHost,
847 kListUsbFilters,
848 kListSystemProperties,
849 kListDhcpServers,
850 kListExtPacks,
851 kListGroups,
852 kListNatNetworks,
853 kListVideoInputDevices,
854 kListScreenShotFormats
855};
856
857
858/**
859 * Produces the specified listing.
860 *
861 * @returns S_OK or some COM error code that has been reported in full.
862 * @param enmList The list to produce.
863 * @param fOptLong Long (@c true) or short list format.
864 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
865 */
866static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &pVirtualBox)
867{
868 HRESULT rc = S_OK;
869 switch (enmCommand)
870 {
871 case kListNotSpecified:
872 AssertFailed();
873 return E_FAIL;
874
875 case kListVMs:
876 {
877 /*
878 * Get the list of all registered VMs
879 */
880 com::SafeIfaceArray<IMachine> machines;
881 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
882 if (SUCCEEDED(rc))
883 {
884 /*
885 * Iterate through the collection
886 */
887 for (size_t i = 0; i < machines.size(); ++i)
888 {
889 if (machines[i])
890 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
891 }
892 }
893 break;
894 }
895
896 case kListRunningVMs:
897 {
898 /*
899 * Get the list of all _running_ VMs
900 */
901 com::SafeIfaceArray<IMachine> machines;
902 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
903 com::SafeArray<MachineState_T> states;
904 if (SUCCEEDED(rc))
905 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
906 if (SUCCEEDED(rc))
907 {
908 /*
909 * Iterate through the collection
910 */
911 for (size_t i = 0; i < machines.size(); ++i)
912 {
913 if (machines[i])
914 {
915 MachineState_T machineState = states[i];
916 switch (machineState)
917 {
918 case MachineState_Running:
919 case MachineState_Teleporting:
920 case MachineState_LiveSnapshotting:
921 case MachineState_Paused:
922 case MachineState_TeleportingPausedVM:
923 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
924 break;
925 }
926 }
927 }
928 }
929 break;
930 }
931
932 case kListOsTypes:
933 {
934 com::SafeIfaceArray<IGuestOSType> coll;
935 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
936 if (SUCCEEDED(rc))
937 {
938 /*
939 * Iterate through the collection.
940 */
941 for (size_t i = 0; i < coll.size(); ++i)
942 {
943 ComPtr<IGuestOSType> guestOS;
944 guestOS = coll[i];
945 Bstr guestId;
946 guestOS->COMGETTER(Id)(guestId.asOutParam());
947 RTPrintf("ID: %ls\n", guestId.raw());
948 Bstr guestDescription;
949 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
950 RTPrintf("Description: %ls\n", guestDescription.raw());
951 Bstr familyId;
952 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
953 RTPrintf("Family ID: %ls\n", familyId.raw());
954 Bstr familyDescription;
955 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
956 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
957 BOOL is64Bit;
958 guestOS->COMGETTER(Is64Bit)(&is64Bit);
959 RTPrintf("64 bit: %RTbool\n", is64Bit);
960 RTPrintf("\n");
961 }
962 }
963 break;
964 }
965
966 case kListHostDvds:
967 {
968 ComPtr<IHost> host;
969 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
970 com::SafeIfaceArray<IMedium> coll;
971 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
972 if (SUCCEEDED(rc))
973 {
974 for (size_t i = 0; i < coll.size(); ++i)
975 {
976 ComPtr<IMedium> dvdDrive = coll[i];
977 Bstr uuid;
978 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
979 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
980 Bstr location;
981 dvdDrive->COMGETTER(Location)(location.asOutParam());
982 RTPrintf("Name: %ls\n\n", location.raw());
983 }
984 }
985 break;
986 }
987
988 case kListHostFloppies:
989 {
990 ComPtr<IHost> host;
991 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
992 com::SafeIfaceArray<IMedium> coll;
993 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
994 if (SUCCEEDED(rc))
995 {
996 for (size_t i = 0; i < coll.size(); ++i)
997 {
998 ComPtr<IMedium> floppyDrive = coll[i];
999 Bstr uuid;
1000 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1001 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1002 Bstr location;
1003 floppyDrive->COMGETTER(Location)(location.asOutParam());
1004 RTPrintf("Name: %ls\n\n", location.raw());
1005 }
1006 }
1007 break;
1008 }
1009
1010 case kListInternalNetworks:
1011 rc = listInternalNetworks(pVirtualBox);
1012 break;
1013
1014 case kListBridgedInterfaces:
1015#if defined(VBOX_WITH_NETFLT)
1016 case kListHostOnlyInterfaces:
1017#endif
1018 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1019 break;
1020
1021 case kListHostInfo:
1022 rc = listHostInfo(pVirtualBox);
1023 break;
1024
1025 case kListHostCpuIDs:
1026 {
1027 ComPtr<IHost> Host;
1028 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
1029
1030 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
1031 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
1032 static uint32_t const s_auCpuIdRanges[] =
1033 {
1034 UINT32_C(0x00000000), UINT32_C(0x0000007f),
1035 UINT32_C(0x80000000), UINT32_C(0x8000007f),
1036 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
1037 };
1038 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
1039 {
1040 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
1041 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
1042 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
1043 continue;
1044 cLeafs++;
1045 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
1046 {
1047 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
1048 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
1049 }
1050 }
1051 break;
1052 }
1053
1054 case kListHddBackends:
1055 rc = listHddBackends(pVirtualBox);
1056 break;
1057
1058 case kListHdds:
1059 {
1060 com::SafeIfaceArray<IMedium> hdds;
1061 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
1062 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
1063 break;
1064 }
1065
1066 case kListDvds:
1067 {
1068 com::SafeIfaceArray<IMedium> dvds;
1069 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
1070 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
1071 break;
1072 }
1073
1074 case kListFloppies:
1075 {
1076 com::SafeIfaceArray<IMedium> floppies;
1077 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
1078 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
1079 break;
1080 }
1081
1082 case kListUsbHost:
1083 rc = listUsbHost(pVirtualBox);
1084 break;
1085
1086 case kListUsbFilters:
1087 rc = listUsbFilters(pVirtualBox);
1088 break;
1089
1090 case kListSystemProperties:
1091 rc = listSystemProperties(pVirtualBox);
1092 break;
1093
1094 case kListDhcpServers:
1095 {
1096 com::SafeIfaceArray<IDHCPServer> svrs;
1097 CHECK_ERROR(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
1098 for (size_t i = 0; i < svrs.size(); ++i)
1099 {
1100 ComPtr<IDHCPServer> svr = svrs[i];
1101 Bstr netName;
1102 svr->COMGETTER(NetworkName)(netName.asOutParam());
1103 RTPrintf("NetworkName: %ls\n", netName.raw());
1104 Bstr ip;
1105 svr->COMGETTER(IPAddress)(ip.asOutParam());
1106 RTPrintf("IP: %ls\n", ip.raw());
1107 Bstr netmask;
1108 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
1109 RTPrintf("NetworkMask: %ls\n", netmask.raw());
1110 Bstr lowerIp;
1111 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
1112 RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw());
1113 Bstr upperIp;
1114 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
1115 RTPrintf("upperIPAddress: %ls\n", upperIp.raw());
1116 BOOL fEnabled;
1117 svr->COMGETTER(Enabled)(&fEnabled);
1118 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1119 RTPrintf("\n");
1120 }
1121 break;
1122 }
1123
1124 case kListExtPacks:
1125 rc = listExtensionPacks(pVirtualBox);
1126 break;
1127
1128 case kListGroups:
1129 rc = listGroups(pVirtualBox);
1130 break;
1131
1132 case kListNatNetworks:
1133 {
1134 com::SafeIfaceArray<INATNetwork> nets;
1135 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
1136 for (size_t i = 0; i < nets.size(); ++i)
1137 {
1138 ComPtr<INATNetwork> net = nets[i];
1139 Bstr netName;
1140 net->COMGETTER(NetworkName)(netName.asOutParam());
1141 RTPrintf("NetworkName: %ls\n", netName.raw());
1142 Bstr gateway;
1143 net->COMGETTER(Gateway)(gateway.asOutParam());
1144 RTPrintf("IP: %ls\n", gateway.raw());
1145 Bstr network;
1146 net->COMGETTER(Network)(network.asOutParam());
1147 RTPrintf("Network: %ls\n", network.raw());
1148 BOOL fEnabled;
1149 net->COMGETTER(IPv6Enabled)(&fEnabled);
1150 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
1151 Bstr ipv6prefix;
1152 net->COMGETTER(Network)(network.asOutParam());
1153 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
1154 net->COMGETTER(NeedDhcpServer)(&fEnabled);
1155 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
1156 net->COMGETTER(Enabled)(&fEnabled);
1157 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
1158
1159#define PRINT_STRING_ARRAY(title) \
1160 if (strs.size() > 0) \
1161 { \
1162 RTPrintf(title); \
1163 size_t j = 0; \
1164 for (;j < strs.size(); ++j) \
1165 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
1166 }
1167
1168 com::SafeArray<BSTR> strs;
1169
1170 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
1171 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
1172 strs.setNull();
1173
1174 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
1175 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
1176 strs.setNull();
1177
1178 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
1179 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
1180 strs.setNull();
1181
1182#undef PRINT_STRING_ARRAY
1183 RTPrintf("\n");
1184 }
1185 break;
1186 }
1187
1188 case kListVideoInputDevices:
1189 rc = listVideoInputDevices(pVirtualBox);
1190 break;
1191
1192 case kListScreenShotFormats:
1193 rc = listScreenShotFormats(pVirtualBox);
1194 break;
1195
1196 /* No default here, want gcc warnings. */
1197
1198 } /* end switch */
1199
1200 return rc;
1201}
1202
1203/**
1204 * Handles the 'list' command.
1205 *
1206 * @returns Appropriate exit code.
1207 * @param a Handler argument.
1208 */
1209int handleList(HandlerArg *a)
1210{
1211 bool fOptLong = false;
1212 bool fOptMultiple = false;
1213 enum enmListType enmOptCommand = kListNotSpecified;
1214
1215 static const RTGETOPTDEF s_aListOptions[] =
1216 {
1217 { "--long", 'l', RTGETOPT_REQ_NOTHING },
1218 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
1219 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
1220 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
1221 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
1222 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
1223 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
1224 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
1225 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
1226 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
1227#if defined(VBOX_WITH_NETFLT)
1228 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
1229#endif
1230 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1231 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
1232 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
1233 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
1234 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
1235 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
1236 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
1237 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
1238 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
1239 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
1240 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
1241 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
1242 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
1243 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
1244 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
1245 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
1246 };
1247
1248 int ch;
1249 RTGETOPTUNION ValueUnion;
1250 RTGETOPTSTATE GetState;
1251 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
1252 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1253 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1254 {
1255 switch (ch)
1256 {
1257 case 'l': /* --long */
1258 fOptLong = true;
1259 break;
1260
1261 case 'm':
1262 fOptMultiple = true;
1263 if (enmOptCommand == kListNotSpecified)
1264 break;
1265 ch = enmOptCommand;
1266 /* fall thru */
1267
1268 case kListVMs:
1269 case kListRunningVMs:
1270 case kListOsTypes:
1271 case kListHostDvds:
1272 case kListHostFloppies:
1273 case kListInternalNetworks:
1274 case kListBridgedInterfaces:
1275#if defined(VBOX_WITH_NETFLT)
1276 case kListHostOnlyInterfaces:
1277#endif
1278 case kListHostInfo:
1279 case kListHostCpuIDs:
1280 case kListHddBackends:
1281 case kListHdds:
1282 case kListDvds:
1283 case kListFloppies:
1284 case kListUsbHost:
1285 case kListUsbFilters:
1286 case kListSystemProperties:
1287 case kListDhcpServers:
1288 case kListExtPacks:
1289 case kListGroups:
1290 case kListNatNetworks:
1291 case kListVideoInputDevices:
1292 case kListScreenShotFormats:
1293 enmOptCommand = (enum enmListType)ch;
1294 if (fOptMultiple)
1295 {
1296 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);
1297 if (FAILED(hrc))
1298 return 1;
1299 }
1300 break;
1301
1302 case VINF_GETOPT_NOT_OPTION:
1303 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1304
1305 default:
1306 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1307 }
1308 }
1309
1310 /*
1311 * If not in multiple list mode, we have to produce the list now.
1312 */
1313 if (enmOptCommand == kListNotSpecified)
1314 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1315 if (!fOptMultiple)
1316 {
1317 HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);
1318 if (FAILED(hrc))
1319 return 1;
1320 }
1321
1322 return 0;
1323}
1324
1325#endif /* !VBOX_ONLY_DOCS */
1326/* 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