Changeset 27857 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Mar 31, 2010 9:02:32 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r27688 r27857 87 87 LISTUSBFILTERS, 88 88 LISTSYSTEMPROPERTIES, 89 LISTDHCPSERVERS 89 LISTDHCPSERVERS, 90 LISTNATPFS 90 91 }; 91 92 … … 112 113 { "usbfilters", LISTUSBFILTERS, RTGETOPT_REQ_NOTHING }, 113 114 { "systemproperties", LISTSYSTEMPROPERTIES, RTGETOPT_REQ_NOTHING }, 114 { "dhcpservers", LISTDHCPSERVERS, RTGETOPT_REQ_NOTHING } 115 { "dhcpservers", LISTDHCPSERVERS, RTGETOPT_REQ_NOTHING }, 116 { "natrules", LISTNATPFS, RTGETOPT_REQ_STRING|RTGETOPT_FLAG_INDEX } 115 117 }; 116 118 … … 136 138 break; 137 139 140 case LISTNATPFS: 141 if (a->argc < 2) 142 return errorSyntax(USAGE_LIST, "Missing vm name for \"list\" %S.\n", a->argv[0]); 143 138 144 case LISTVMS: 139 145 case LISTRUNNINGVMS: … … 920 926 } 921 927 break; 928 case LISTNATPFS: 929 { 930 ComPtr<IMachine> machine; 931 ComPtr<INetworkAdapter> nic; 932 ComPtr<INATEngine> driver; 933 com::SafeArray<BSTR> rules; 934 if (!Guid(Bstr(a->argv[1])).isEmpty()) 935 { 936 CHECK_ERROR_RET(a->virtualBox, GetMachine(Bstr(a->argv[1]), machine.asOutParam()), 1); 937 } 938 else 939 { 940 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[1]), machine.asOutParam()), 1); 941 } 942 943 ASSERT(machine); 944 945 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(RTStrToUInt32(&a->argv[0][8]) - 1, nic.asOutParam())); 946 ASSERT(nic); 947 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 948 CHECK_ERROR(driver, COMGETTER(Redirects)(ComSafeArrayAsOutParam (rules))); 949 for (size_t i = 0; i < rules.size(); ++ i) 950 { 951 uint16_t port = 0; 952 BSTR r = rules[i]; 953 Utf8Str utf = Utf8Str(r); 954 Utf8Str strName; 955 Utf8Str strProto; 956 Utf8Str strHostPort; 957 Utf8Str strHostIP; 958 Utf8Str strGuestPort; 959 Utf8Str strGuestIP; 960 size_t pos, ppos; 961 pos = ppos = 0; 962 #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \ 963 do { \ 964 pos = str.find(",", ppos); \ 965 if (pos == Utf8Str::npos) \ 966 { \ 967 Log(( #res " extracting from %s is failed\n", str.raw())); \ 968 return E_INVALIDARG; \ 969 } \ 970 res = str.substr(ppos, pos - ppos); \ 971 Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \ 972 ppos = pos + 1; \ 973 }while (0) 974 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos); 975 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos); 976 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos); 977 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos); 978 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos); 979 strGuestPort = utf.substr(ppos, utf.length() - ppos); 980 #undef ITERATE_TO_NEXT_TERM 981 switch (strProto.toUInt32()) 982 { 983 case NATProtocol_TCP: 984 strProto = "tcp"; 985 break; 986 case NATProtocol_UDP: 987 strProto = "udp"; 988 break; 989 default: 990 strProto = "unk"; 991 break; 992 } 993 RTPrintf("%s:%s:%s:%s:%s:%s\n", strName.raw(), strProto.raw(), 994 strHostIP.isEmpty() ? "": strHostIP.raw(), strHostPort.raw(), 995 strGuestIP.isEmpty() ? "": strGuestIP.raw(), strGuestPort.raw()); 996 } 997 998 } 999 break; 922 1000 } // end switch 923 1001 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp
r27822 r27857 115 115 MODIFYVM_INTNET, 116 116 MODIFYVM_NATNET, 117 MODIFYVM_NATBINDIP, 118 MODIFYVM_NATSETTINGS, 119 MODIFYVM_NATPF, 120 MODIFYVM_NATTFTPPREFIX, 121 MODIFYVM_NATTFTPFILE, 122 MODIFYVM_NATTFTPSERVER, 123 MODIFYVM_NATDNSPASSDOMAIN, 124 MODIFYVM_NATDNSPROXY, 125 MODIFYVM_NATDNSHOSTRESOLVER, 117 126 MODIFYVM_MACADDRESS, 118 127 MODIFYVM_HIDPTR, … … 210 219 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 211 220 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 221 { "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 222 { "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX }, 223 { "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 224 { "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 225 { "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 226 { "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 227 { "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX }, 228 { "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX }, 229 { "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX }, 212 230 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX }, 213 231 { "--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING }, … … 1207 1225 { 1208 1226 ComPtr<INetworkAdapter> nic; 1227 ComPtr<INATEngine> driver; 1209 1228 1210 1229 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1211 1230 ASSERT(nic); 1212 1231 1213 CHECK_ERROR(nic, COMSETTER(NATNetwork)(Bstr(ValueUnion.psz))); 1214 break; 1215 } 1216 1232 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1233 CHECK_ERROR(driver, COMSETTER(Network)(Bstr(ValueUnion.psz))); 1234 break; 1235 } 1236 1237 case MODIFYVM_NATBINDIP: 1238 { 1239 ComPtr<INetworkAdapter> nic; 1240 ComPtr<INATEngine> driver; 1241 1242 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1243 ASSERT(nic); 1244 1245 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1246 CHECK_ERROR(driver, COMSETTER(HostIP)(Bstr(ValueUnion.psz))); 1247 break; 1248 } 1249 1250 #define ITERATE_TO_NEXT_TERM(ch) \ 1251 do { \ 1252 while (*ch != ',') { \ 1253 if (*ch == 0) { \ 1254 return errorSyntax(USAGE_MODIFYVM, \ 1255 "Missing or Invalid argument to '%s'", \ 1256 GetOptState.pDef->pszLong); \ 1257 } \ 1258 ch++; \ 1259 } \ 1260 *ch = '\0'; \ 1261 ch++; \ 1262 }while(0) 1263 case MODIFYVM_NATSETTINGS: 1264 { 1265 ComPtr<INetworkAdapter> nic; 1266 ComPtr<INATEngine> driver; 1267 char *strMtu; 1268 char *strSockSnd; 1269 char *strSockRcv; 1270 char *strTcpSnd; 1271 char *strTcpRcv; 1272 char *strRaw = RTStrDup(ValueUnion.psz); 1273 char *ch = strRaw; 1274 strMtu = ch; 1275 ITERATE_TO_NEXT_TERM(ch); 1276 strSockSnd = ch; 1277 ITERATE_TO_NEXT_TERM(ch); 1278 strSockRcv = ch; 1279 ITERATE_TO_NEXT_TERM(ch); 1280 strTcpSnd = ch; 1281 ITERATE_TO_NEXT_TERM(ch); 1282 strTcpRcv = ch; 1283 1284 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1285 ASSERT(nic); 1286 1287 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1288 CHECK_ERROR(driver, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv), 1289 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv))); 1290 break; 1291 } 1292 1293 1294 case MODIFYVM_NATPF: 1295 { 1296 ComPtr<INetworkAdapter> nic; 1297 ComPtr<INATEngine> driver; 1298 1299 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1300 ASSERT(nic); 1301 1302 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1303 /* format name:proto:hostip:hostport:guestip:guestport*/ 1304 if (RTStrCmp(ValueUnion.psz, "delete") != 0) 1305 { 1306 char *strName; 1307 char *strProto; 1308 char *strHostIp; 1309 char *strHostPort; 1310 char *strGuestIp; 1311 char *strGuestPort; 1312 char *strRaw = RTStrDup(ValueUnion.psz); 1313 char *ch = strRaw; 1314 strName = ch; 1315 ITERATE_TO_NEXT_TERM(ch); 1316 strProto = ch; 1317 ITERATE_TO_NEXT_TERM(ch); 1318 strHostIp = ch; 1319 ITERATE_TO_NEXT_TERM(ch); 1320 strHostPort = ch; 1321 ITERATE_TO_NEXT_TERM(ch); 1322 strGuestIp = ch; 1323 ITERATE_TO_NEXT_TERM(ch); 1324 strGuestPort = ch; 1325 uint32_t proto; 1326 if (RTStrICmp(strProto, "udp") == 0) 1327 proto = NATProtocol_UDP; 1328 else if (RTStrICmp(strProto, "tcp") == 0) 1329 proto = NATProtocol_TCP; 1330 else 1331 { 1332 errorArgument("Invalid proto '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex); 1333 rc = E_FAIL; 1334 break; 1335 } 1336 CHECK_ERROR(driver, AddRedirect(Bstr(strName), proto, Bstr(strHostIp), 1337 RTStrToUInt16(strHostPort), Bstr(strGuestIp), RTStrToUInt16(strGuestPort))); 1338 } 1339 else 1340 { 1341 /* delete NAT Rule operation */ 1342 int vrc; 1343 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING); 1344 if (RT_FAILURE(vrc)) 1345 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters"); 1346 CHECK_ERROR(driver, RemoveRedirect(Bstr(ValueUnion.psz))); 1347 } 1348 break; 1349 } 1350 #undef ITERATE_TO_NEXT_TERM 1351 1352 case MODIFYVM_NATTFTPPREFIX: 1353 { 1354 ComPtr<INetworkAdapter> nic; 1355 ComPtr<INATEngine> driver; 1356 1357 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1358 ASSERT(nic); 1359 1360 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1361 CHECK_ERROR(driver, COMSETTER(TftpPrefix)(Bstr(ValueUnion.psz))); 1362 break; 1363 } 1364 1365 case MODIFYVM_NATTFTPFILE: 1366 { 1367 ComPtr<INetworkAdapter> nic; 1368 ComPtr<INATEngine> driver; 1369 1370 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1371 ASSERT(nic); 1372 1373 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1374 CHECK_ERROR(driver, COMSETTER(TftpBootFile)(Bstr(ValueUnion.psz))); 1375 break; 1376 } 1377 1378 case MODIFYVM_NATTFTPSERVER: 1379 { 1380 ComPtr<INetworkAdapter> nic; 1381 ComPtr<INATEngine> driver; 1382 1383 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1384 ASSERT(nic); 1385 1386 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1387 CHECK_ERROR(driver, COMSETTER(TftpNextServer)(Bstr(ValueUnion.psz))); 1388 break; 1389 } 1390 case MODIFYVM_NATDNSPASSDOMAIN: 1391 { 1392 ComPtr<INetworkAdapter> nic; 1393 ComPtr<INATEngine> driver; 1394 1395 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1396 ASSERT(nic); 1397 1398 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1399 CHECK_ERROR(driver, COMSETTER(DnsPassDomain)(ValueUnion.f)); 1400 break; 1401 } 1402 1403 case MODIFYVM_NATDNSPROXY: 1404 { 1405 ComPtr<INetworkAdapter> nic; 1406 ComPtr<INATEngine> driver; 1407 1408 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1409 ASSERT(nic); 1410 1411 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1412 CHECK_ERROR(driver, COMSETTER(DnsProxy)(ValueUnion.f)); 1413 break; 1414 } 1415 1416 case MODIFYVM_NATDNSHOSTRESOLVER: 1417 { 1418 ComPtr<INetworkAdapter> nic; 1419 ComPtr<INATEngine> driver; 1420 1421 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam())); 1422 ASSERT(nic); 1423 1424 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam())); 1425 CHECK_ERROR(driver, COMSETTER(DnsUseHostResolver)(ValueUnion.f)); 1426 break; 1427 } 1217 1428 case MODIFYVM_MACADDRESS: 1218 1429 {
Note:
See TracChangeset
for help on using the changeset viewer.