VirtualBox

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

Last change on this file since 63300 was 63300, checked in by vboxsync, 8 years ago

VBoxManage: warnings

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