VirtualBox

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

Last change on this file since 56103 was 55843, checked in by vboxsync, 10 years ago

Frontends/VBoxManage: allow configuring the VBoxSVC release logging level, plus documentation

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