Changeset 28345 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Apr 15, 2010 5:40:43 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r28192 r28345 120 120 " hostcpuids|hddbackends|hdds|dvds|floppies|\n" 121 121 " usbhost|usbfilters|systemproperties\n" 122 " natrules<1-N> <name>\n"123 122 "\n"); 124 123 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r28269 r28345 739 739 nic->COMGETTER(MACAddress)(strMACAddress.asOutParam()); 740 740 Utf8Str strAttachment; 741 Utf8Str strNatSettings = ""; 742 Utf8Str strNatForwardings = ""; 741 743 NetworkAttachmentType_T attachment; 742 744 nic->COMGETTER(AttachmentType)(&attachment); … … 752 754 { 753 755 Bstr strNetwork; 754 nic->COMGETTER(NATNetwork)(strNetwork.asOutParam()); 756 ComPtr<INATEngine> driver; 757 nic->COMGETTER(NatDriver)(driver.asOutParam()); 758 driver->COMGETTER(Network)(strNetwork.asOutParam()); 759 com::SafeArray<BSTR> forwardings; 760 driver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(forwardings)); 761 strNatForwardings = ""; 762 for (size_t i = 0; i < forwardings.size(); ++i) 763 { 764 bool fSkip = false; 765 uint16_t port = 0; 766 BSTR r = forwardings[i]; 767 Utf8Str utf = Utf8Str(r); 768 Utf8Str strName; 769 Utf8Str strProto; 770 Utf8Str strHostPort; 771 Utf8Str strHostIP; 772 Utf8Str strGuestPort; 773 Utf8Str strGuestIP; 774 size_t pos, ppos; 775 pos = ppos = 0; 776 #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \ 777 do { \ 778 pos = str.find(",", ppos); \ 779 if (pos == Utf8Str::npos) \ 780 { \ 781 Log(( #res " extracting from %s is failed\n", str.raw())); \ 782 fSkip = true; \ 783 } \ 784 res = str.substr(ppos, pos - ppos); \ 785 Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \ 786 ppos = pos + 1; \ 787 } while (0) 788 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos); 789 if (fSkip) continue; 790 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos); 791 if (fSkip) continue; 792 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos); 793 if (fSkip) continue; 794 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos); 795 if (fSkip) continue; 796 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos); 797 if (fSkip) continue; 798 strGuestPort = utf.substr(ppos, utf.length() - ppos); 799 #undef ITERATE_TO_NEXT_TERM 800 switch (strProto.toUInt32()) 801 { 802 case NATProtocol_TCP: 803 strProto = "tcp"; 804 break; 805 case NATProtocol_UDP: 806 strProto = "udp"; 807 break; 808 default: 809 strProto = "unk"; 810 break; 811 } 812 if (details == VMINFO_MACHINEREADABLE) 813 { 814 strNatForwardings = Utf8StrFmt("%sForwarding(%d)=\"%s,%s,%s,%s,%s,%s\"\n", 815 strNatForwardings.raw(), i, strName.raw(), strProto.raw(), 816 strHostIP.isEmpty() ? "": strHostIP.raw(), strHostPort.raw(), 817 strGuestIP.isEmpty() ? "": strGuestIP.raw(), strGuestPort.raw()); 818 } 819 else 820 { 821 strNatForwardings = Utf8StrFmt("%sNIC %d Rule(%d): name = %s, protocol = %s," 822 " host ip = %s, host port = %s, guest ip = %s, guest port = %s\n", 823 strNatForwardings.raw(), currentNIC + 1, i, strName.raw(), strProto.raw(), 824 strHostIP.isEmpty() ? "": strHostIP.raw(), strHostPort.raw(), 825 strGuestIP.isEmpty() ? "": strGuestIP.raw(), strGuestPort.raw()); 826 } 827 } 828 ULONG mtu = 0; 829 ULONG sockSnd = 0; 830 ULONG sockRcv = 0; 831 ULONG tcpSnd = 0; 832 ULONG tcpRcv = 0; 833 driver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); 834 755 835 if (details == VMINFO_MACHINEREADABLE) 756 836 { 757 RTPrintf("natnet%d=\"%lS\"\n", currentNIC + 1, strNetwork. raw());837 RTPrintf("natnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.length() ? strNetwork.raw(): Bstr("nat").raw()); 758 838 strAttachment = "nat"; 839 strNatSettings = Utf8StrFmt("mtu=\"%d\"\nsockSnd=\"%d\"\nsockRcv=\"%d\"\ntcpWndSnd=\"%d\"\ntcpWndRcv=\"%d\"\n", 840 mtu, sockSnd ? sockSnd : 64, sockRcv ? sockRcv : 64 , tcpSnd ? tcpSnd : 64, tcpRcv ? tcpRcv : 64); 759 841 } 760 else if (!strNetwork.isEmpty())761 strAttachment = Utf8StrFmt("NAT (%lS)", strNetwork.raw());762 842 else 843 { 763 844 strAttachment = "NAT"; 845 strNatSettings = Utf8StrFmt("NIC %d Settings: MTU: %d, Socket( send: %d, receive: %d), TCP Window( send:%d, receive: %d)\n", 846 currentNIC + 1, mtu, sockSnd ? sockSnd : 64, sockRcv ? sockRcv : 64 , tcpSnd ? tcpSnd : 64, tcpRcv ? tcpRcv : 64); 847 } 764 848 break; 765 849 } … … 875 959 ulLineSpeed / 1000, 876 960 (int)ulBootPriority); 961 if (strNatSettings.length()) 962 RTPrintf(strNatSettings.raw()); 963 if (strNatForwardings.length()) 964 RTPrintf(strNatForwardings.raw()); 877 965 } 878 966 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r28255 r28345 192 192 LISTUSBFILTERS, 193 193 LISTSYSTEMPROPERTIES, 194 LISTDHCPSERVERS, 195 LISTNATPFS 194 LISTDHCPSERVERS 196 195 }; 197 196 … … 219 218 { "systemproperties", LISTSYSTEMPROPERTIES, RTGETOPT_REQ_NOTHING }, 220 219 { "dhcpservers", LISTDHCPSERVERS, RTGETOPT_REQ_NOTHING }, 221 { "natrules", LISTNATPFS, RTGETOPT_REQ_STRING|RTGETOPT_FLAG_INDEX }222 220 }; 223 221 … … 242 240 fOptLong = true; 243 241 break; 244 245 case LISTNATPFS:246 if (a->argc < 2)247 return errorSyntax(USAGE_LIST, "Missing vm name for \"list\" %S.\n", a->argv[0]);248 242 249 243 case LISTVMS: … … 977 971 } 978 972 break; 979 case LISTNATPFS:980 {981 ComPtr<IMachine> machine;982 ComPtr<INetworkAdapter> nic;983 ComPtr<INATEngine> driver;984 com::SafeArray<BSTR> rules;985 if (!Guid(Bstr(a->argv[1])).isEmpty())986 {987 CHECK_ERROR_RET(a->virtualBox, GetMachine(Bstr(a->argv[1]), machine.asOutParam()), 1);988 }989 else990 {991 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[1]), machine.asOutParam()), 1);992 }993 994 ASSERT(machine);995 996 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(RTStrToUInt32(&a->argv[0][8]) - 1, nic.asOutParam()));997 ASSERT(nic);998 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));999 CHECK_ERROR(driver, COMGETTER(Redirects)(ComSafeArrayAsOutParam(rules)));1000 for (size_t i = 0; i < rules.size(); ++i)1001 {1002 uint16_t port = 0;1003 BSTR r = rules[i];1004 Utf8Str utf = Utf8Str(r);1005 Utf8Str strName;1006 Utf8Str strProto;1007 Utf8Str strHostPort;1008 Utf8Str strHostIP;1009 Utf8Str strGuestPort;1010 Utf8Str strGuestIP;1011 size_t pos, ppos;1012 pos = ppos = 0;1013 #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \1014 do { \1015 pos = str.find(",", ppos); \1016 if (pos == Utf8Str::npos) \1017 { \1018 Log(( #res " extracting from %s is failed\n", str.raw())); \1019 return E_INVALIDARG; \1020 } \1021 res = str.substr(ppos, pos - ppos); \1022 Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \1023 ppos = pos + 1; \1024 } while (0)1025 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);1026 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);1027 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);1028 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);1029 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);1030 strGuestPort = utf.substr(ppos, utf.length() - ppos);1031 #undef ITERATE_TO_NEXT_TERM1032 switch (strProto.toUInt32())1033 {1034 case NATProtocol_TCP:1035 strProto = "tcp";1036 break;1037 case NATProtocol_UDP:1038 strProto = "udp";1039 break;1040 default:1041 strProto = "unk";1042 break;1043 }1044 RTPrintf("%s:%s:%s:%s:%s:%s\n", strName.raw(), strProto.raw(),1045 strHostIP.isEmpty() ? "": strHostIP.raw(), strHostPort.raw(),1046 strGuestIP.isEmpty() ? "": strGuestIP.raw(), strGuestPort.raw());1047 }1048 1049 }1050 break;1051 973 } // end switch 1052 974
Note:
See TracChangeset
for help on using the changeset viewer.