Changeset 79748 in vbox
- Timestamp:
- Jul 12, 2019 11:01:35 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r78512 r79748 158 158 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam()); 159 159 RTPrintf("GUID: %ls\n", interfaceGuid.raw()); 160 BOOL bDHCPEnabled;161 networkInterface->COMGETTER(DHCPEnabled)(& bDHCPEnabled);162 RTPrintf("DHCP: %s\n", bDHCPEnabled ? "Enabled" : "Disabled");160 BOOL fDHCPEnabled = FALSE; 161 networkInterface->COMGETTER(DHCPEnabled)(&fDHCPEnabled); 162 RTPrintf("DHCP: %s\n", fDHCPEnabled ? "Enabled" : "Disabled"); 163 163 164 164 Bstr IPAddress; … … 180 180 networkInterface->COMGETTER(MediumType)(&Type); 181 181 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type)); 182 BOOL fWireless ;182 BOOL fWireless = FALSE; 183 183 networkInterface->COMGETTER(Wireless)(&fWireless); 184 184 RTPrintf("Wireless: %s\n", fWireless ? "Yes" : "No"); … … 786 786 787 787 /** 788 * Helper function for querying and displaying DHCP option for an adapter. 789 * 790 * @returns See produceList. 791 * @param pSrv Smart pointer to IDHCPServer. 792 * @param vmSlot String identifying the adapter, like '[vmname]:slot' 793 */ 794 static HRESULT listVmSlotDhcpOptions(const ComPtr<IDHCPServer> pSrv, const Utf8Str& vmSlot) 795 { 796 RTCList<RTCString> lstParts = vmSlot.split(":"); 797 if (lstParts.size() < 2) 798 return E_INVALIDARG; 799 if (lstParts[0].length() < 2 || !lstParts[0].startsWith("[") || !lstParts[0].endsWith("]")) 800 return E_INVALIDARG; 801 Bstr vmName(lstParts[0].substr(1, lstParts[0].length()-2)); 802 ULONG uSlot = lstParts[1].toUInt32(); 803 com::SafeArray<BSTR> options; 804 CHECK_ERROR2I_RET(pSrv, GetVmSlotOptions(vmName.raw(), uSlot, ComSafeArrayAsOutParam(options)), hrcCheck); 805 if (options.size()) 806 RTPrintf("Options for NIC %d of '%ls':\n", uSlot + 1, vmName.raw()); 807 for (size_t i = 0; i < options.size(); ++i) 808 RTPrintf(" %ls\n", options[i]); 788 * Helper for listDhcpServers() that shows a DHCP configuration. 789 */ 790 static HRESULT showDhcpConfig(ComPtr<IDHCPConfig> ptrConfig) 791 { 792 HRESULT hrcRet = S_OK; 793 794 ULONG secs = 0; 795 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MinLeaseTime)(&secs), hrcRet = hrcCheck); 796 if (secs == 0) 797 RTPrintf(" minLeaseTime: default\n"); 798 else 799 RTPrintf(" minLeaseTime: %u sec\n", secs); 800 801 secs = 0; 802 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(DefaultLeaseTime)(&secs), hrcRet = hrcCheck); 803 if (secs == 0) 804 RTPrintf(" defaultLeaseTime: default\n"); 805 else 806 RTPrintf(" defaultLeaseTime: %u sec\n", secs); 807 808 secs = 0; 809 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MaxLeaseTime)(&secs), hrcRet = hrcCheck); 810 if (secs == 0) 811 RTPrintf(" maxLeaseTime: default\n"); 812 else 813 RTPrintf(" maxLeaseTime: %u sec\n", secs); 814 815 com::SafeArray<DhcpOpt_T> Options; 816 com::SafeArray<DHCPOptionEncoding_T> Encodings; 817 com::SafeArray<BSTR> Values; 818 HRESULT hrc; 819 CHECK_ERROR2_STMT(hrc, ptrConfig, GetAllOptions(ComSafeArrayAsOutParam(Options), 820 ComSafeArrayAsOutParam(Encodings), 821 ComSafeArrayAsOutParam(Values)), hrcRet = hrc); 822 if (FAILED(hrc)) 823 RTPrintf(" DHCP options: %Rhrc\n", hrc); 824 else if (Options.size() != Encodings.size() || Options.size() != Values.size()) 825 { 826 RTPrintf(" DHCP options: Return count mismatch: %zu, %zu, %zu\n", Options.size(), Encodings.size(), Values.size()); 827 hrcRet = E_FAIL; 828 } 829 else if (Options.size() == 0) 830 RTPrintf(" DHCP options: None\n"); 831 else 832 for (size_t i = 0; i < Options.size(); i++) 833 { 834 switch (Encodings[i]) 835 { 836 case DHCPOptionEncoding_Legacy: 837 RTPrintf(" %3d/legacy: %ls\n", Options[i], Values[i]); 838 break; 839 case DHCPOptionEncoding_Hex: 840 RTPrintf(" %3d/hex: %ls\n", Options[i], Values[i]); 841 break; 842 default: 843 RTPrintf(" %3d/%u?: %ls\n", Options[i], Encodings[i], Values[i]); 844 break; 845 } 846 } 809 847 810 848 return S_OK; … … 820 858 static HRESULT listDhcpServers(const ComPtr<IVirtualBox> &pVirtualBox) 821 859 { 822 HRESULT rc= S_OK;860 HRESULT hrcRet = S_OK; 823 861 com::SafeIfaceArray<IDHCPServer> svrs; 824 CHECK_ERROR _RET(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)), rc);862 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)), hrcCheck); 825 863 for (size_t i = 0; i < svrs.size(); ++i) 826 864 { 865 if (i > 0) 866 RTPrintf("\n"); 867 827 868 ComPtr<IDHCPServer> svr = svrs[i]; 828 Bstr netName; 829 svr->COMGETTER(NetworkName)(netName.asOutParam()); 830 RTPrintf("NetworkName: %ls\n", netName.raw()); 831 Bstr ip; 832 svr->COMGETTER(IPAddress)(ip.asOutParam()); 833 RTPrintf("IP: %ls\n", ip.raw()); 834 Bstr netmask; 835 svr->COMGETTER(NetworkMask)(netmask.asOutParam()); 836 RTPrintf("NetworkMask: %ls\n", netmask.raw()); 837 Bstr lowerIp; 838 svr->COMGETTER(LowerIP)(lowerIp.asOutParam()); 839 RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw()); 840 Bstr upperIp; 841 svr->COMGETTER(UpperIP)(upperIp.asOutParam()); 842 RTPrintf("upperIPAddress: %ls\n", upperIp.raw()); 843 BOOL fEnabled; 844 svr->COMGETTER(Enabled)(&fEnabled); 869 Bstr bstr; 870 CHECK_ERROR2I_STMT(svr, COMGETTER(NetworkName)(bstr.asOutParam()), hrcRet = hrcCheck); 871 RTPrintf("NetworkName: %ls\n", bstr.raw()); 872 873 CHECK_ERROR2I_STMT(svr, COMGETTER(IPAddress)(bstr.asOutParam()), hrcRet = hrcCheck); 874 RTPrintf("Dhcpd IP: %ls\n", bstr.raw()); 875 876 CHECK_ERROR2I_STMT(svr, COMGETTER(LowerIP)(bstr.asOutParam()), hrcRet = hrcCheck); 877 RTPrintf("LowerIPAddress: %ls\n", bstr.raw()); 878 879 CHECK_ERROR2I_STMT(svr, COMGETTER(UpperIP)(bstr.asOutParam()), hrcRet = hrcCheck); 880 RTPrintf("UpperIPAddress: %ls\n", bstr.raw()); 881 882 CHECK_ERROR2I_STMT(svr, COMGETTER(NetworkMask)(bstr.asOutParam()), hrcRet = hrcCheck); 883 RTPrintf("NetworkMask: %ls\n", bstr.raw()); 884 885 BOOL fEnabled = FALSE; 886 CHECK_ERROR2I_STMT(svr, COMGETTER(Enabled)(&fEnabled), hrcRet = hrcCheck); 845 887 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No"); 846 com::SafeArray<BSTR> globalOptions; 847 CHECK_ERROR_BREAK(svr, COMGETTER(GlobalOptions)(ComSafeArrayAsOutParam(globalOptions))); 848 if (globalOptions.size()) 849 { 850 RTPrintf("Global options:\n"); 851 for (size_t j = 0; j < globalOptions.size(); ++j) 852 RTPrintf(" %ls\n", globalOptions[j]); 853 } 854 com::SafeArray<BSTR> vmConfigs; 855 CHECK_ERROR_BREAK(svr, COMGETTER(VmConfigs)(ComSafeArrayAsOutParam(vmConfigs))); 856 for (size_t j = 0; j < vmConfigs.size(); ++j) 857 { 858 rc = listVmSlotDhcpOptions(svr, vmConfigs[j]); 859 if (FAILED(rc)) 860 break; 861 } 862 RTPrintf("\n"); 863 } 864 865 return rc; 888 889 /* Global configuration: */ 890 RTPrintf("Global Configuration:\n"); 891 HRESULT hrc; 892 ComPtr<IDHCPGlobalConfig> ptrGlobal; 893 CHECK_ERROR2_STMT(hrc, svr, COMGETTER(GlobalConfig)(ptrGlobal.asOutParam()), hrcRet = hrc); 894 if (SUCCEEDED(hrc)) 895 { 896 hrc = showDhcpConfig(ptrGlobal); 897 if (FAILED(hrc)) 898 hrcRet = hrc; 899 } 900 901 /* Group configurations: */ 902 com::SafeIfaceArray<IDHCPGroupConfig> Groups; 903 CHECK_ERROR2_STMT(hrc, svr, COMGETTER(GroupConfigs)(ComSafeArrayAsOutParam(Groups)), hrcRet = hrc); 904 if (FAILED(hrc)) 905 RTPrintf("Groups: %Rrc\n", hrc); 906 else if (Groups.size() == 0) 907 RTPrintf("Groups: None\n"); 908 else 909 { 910 for (size_t iGrp = 0; iGrp < Groups.size(); iGrp++) 911 { 912 CHECK_ERROR2I_STMT(Groups[iGrp], COMGETTER(Name)(bstr.asOutParam()), hrcRet = hrcCheck); 913 RTPrintf("Group: %ls\n", bstr.raw()); 914 915 hrc = showDhcpConfig(Groups[iGrp]); 916 if (FAILED(hrc)) 917 hrcRet = hrc; 918 } 919 Groups.setNull(); 920 } 921 922 /* Individual host / NIC configurations: */ 923 com::SafeIfaceArray<IDHCPIndividualConfig> Hosts; 924 CHECK_ERROR2_STMT(hrc, svr, COMGETTER(IndividualConfigs)(ComSafeArrayAsOutParam(Hosts)), hrcRet = hrc); 925 if (FAILED(hrc)) 926 RTPrintf("Individual Configs: %Rrc\n", hrc); 927 else if (Hosts.size() == 0) 928 RTPrintf("Individual Configs: None\n"); 929 else 930 { 931 for (size_t iHost = 0; iHost < Hosts.size(); iHost++) 932 { 933 DHCPConfigScope_T enmScope = DHCPConfigScope_MAC; 934 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Scope)(&enmScope), hrcRet = hrcCheck); 935 936 if (enmScope == DHCPConfigScope_MAC) 937 { 938 CHECK_ERROR2I_STMT(Hosts[i], COMGETTER(MACAddress)(bstr.asOutParam()), hrcRet = hrcCheck); 939 RTPrintf("Individual Config: MAC %ls\n", bstr.raw()); 940 } 941 else 942 { 943 ULONG uSlot = 0; 944 CHECK_ERROR2I_STMT(Hosts[i], COMGETTER(Slot)(&uSlot), hrcRet = hrcCheck); 945 CHECK_ERROR2I_STMT(Hosts[i], COMGETTER(MachineId)(bstr.asOutParam()), hrcRet = hrcCheck); 946 Bstr bstrMACAddress; 947 hrc = Hosts[i]->COMGETTER(MACAddress)(bstrMACAddress.asOutParam()); /* No CHECK_ERROR2 stuff! */ 948 if (SUCCEEDED(hrc)) 949 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %ls\n", bstr.raw(), uSlot, bstrMACAddress.raw()); 950 else 951 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %Rhrc\n", bstr.raw(), uSlot, hrc); 952 } 953 954 CHECK_ERROR2I_STMT(Hosts[i], COMGETTER(FixedAddress)(bstr.asOutParam()), hrcRet = hrcCheck); 955 if (bstr.isNotEmpty()) 956 RTPrintf(" Fixed Address: %ls\n", bstr.raw()); 957 else 958 RTPrintf(" Fixed Address: dynamic\n"); 959 960 hrc = showDhcpConfig(Hosts[i]); 961 if (FAILED(hrc)) 962 hrcRet = hrc; 963 } 964 Hosts.setNull(); 965 } 966 } 967 968 return hrcRet; 866 969 } 867 970
Note:
See TracChangeset
for help on using the changeset viewer.