Changeset 27857 in vbox for trunk/src/VBox/Main/ConsoleImpl2.cpp
- Timestamp:
- Mar 31, 2010 9:02:32 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl2.cpp
r27853 r27857 2531 2531 case NetworkAttachmentType_NAT: 2532 2532 { 2533 ComPtr<INATEngine> natDriver; 2534 hrc = aNetworkAdapter->COMGETTER(NatDriver)(natDriver.asOutParam()); H(); 2533 2535 if (fSniffer) 2534 2536 { … … 2553 2555 STR_FREE(); 2554 2556 2555 hrc = aNetworkAdapter->COMGETTER(NATNetwork)(&str); H(); 2556 if (str && *str) 2557 { 2557 hrc = natDriver->COMGETTER(Network)(&str); H(); 2558 if (str) 2558 2559 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK(); 2559 /* NAT uses its own DHCP implementation */2560 //networkName = Bstr(psz);2561 }2562 2560 STR_FREE(); 2561 hrc = natDriver->COMGETTER(HostIP)(&str); H(); 2562 if (str) 2563 { 2564 rc = CFGMR3InsertStringW(pCfg, "BindIP", str); RC_CHECK(); 2565 } 2566 STR_FREE(); 2567 uint32_t mtu = 0; 2568 uint32_t sockSnd = 0; 2569 uint32_t sockRcv = 0; 2570 uint32_t tcpSnd = 0; 2571 uint32_t tcpRcv = 0; 2572 hrc = natDriver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); H(); 2573 if (mtu) 2574 { 2575 rc = CFGMR3InsertInteger(pCfg, "SlirpMTU", mtu); RC_CHECK(); 2576 } 2577 if (sockRcv) 2578 { 2579 rc = CFGMR3InsertInteger(pCfg, "SockRcv", sockRcv); RC_CHECK(); 2580 } 2581 if (sockSnd) 2582 { 2583 rc = CFGMR3InsertInteger(pCfg, "SockSnd", sockSnd); RC_CHECK(); 2584 } 2585 if (tcpRcv) 2586 { 2587 rc = CFGMR3InsertInteger(pCfg, "TcpRcv", tcpRcv); RC_CHECK(); 2588 } 2589 if (tcpSnd) 2590 { 2591 rc = CFGMR3InsertInteger(pCfg, "TcpSnd", tcpSnd); RC_CHECK(); 2592 } 2593 STR_FREE(); 2594 hrc = natDriver->COMGETTER(TftpPrefix)(&str); H(); 2595 if (str) 2596 { 2597 rc = CFGMR3RemoveValue(pCfg, "TFTPPrefix"); RC_CHECK(); 2598 rc = CFGMR3InsertStringW(pCfg, "TFTPPrefix", str); RC_CHECK(); 2599 } 2600 STR_FREE(); 2601 hrc = natDriver->COMGETTER(TftpBootFile)(&str); H(); 2602 if (str) 2603 { 2604 rc = CFGMR3RemoveValue(pCfg, "BootFile"); RC_CHECK(); 2605 rc = CFGMR3InsertStringW(pCfg, "BootFile", str); RC_CHECK(); 2606 } 2607 STR_FREE(); 2608 hrc = natDriver->COMGETTER(TftpNextServer)(&str); H(); 2609 if (str) 2610 { 2611 rc = CFGMR3InsertStringW(pCfg, "NextServer", str); RC_CHECK(); 2612 } 2613 BOOL fDnsFlag; 2614 hrc = natDriver->COMGETTER(DnsPassDomain)(&fDnsFlag); H(); 2615 rc = CFGMR3InsertInteger(pCfg, "PassDomain", fDnsFlag); RC_CHECK(); 2616 hrc = natDriver->COMGETTER(DnsProxy)(&fDnsFlag); H(); 2617 rc = CFGMR3InsertInteger(pCfg, "DNSProxy", fDnsFlag); RC_CHECK(); 2618 hrc = natDriver->COMGETTER(DnsUseHostResolver)(&fDnsFlag); H(); 2619 rc = CFGMR3InsertInteger(pCfg, "UseHostResolver", fDnsFlag); RC_CHECK(); 2620 /* port-forwarding */ 2621 SafeArray<BSTR> pfs; 2622 hrc = natDriver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(pfs)); H(); 2623 PCFGMNODE pPF = NULL; /* /Devices/Dev/.../Config/PF#0/ */ 2624 for(unsigned int i = 0; i < pfs.size(); ++i) 2625 { 2626 uint16_t port = 0; 2627 BSTR r = pfs[i]; 2628 Utf8Str utf = Utf8Str(r); 2629 Utf8Str strName; 2630 Utf8Str strProto; 2631 Utf8Str strHostPort; 2632 Utf8Str strHostIP; 2633 Utf8Str strGuestPort; 2634 Utf8Str strGuestIP; 2635 size_t pos, ppos; 2636 pos = ppos = 0; 2637 #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \ 2638 do { \ 2639 pos = str.find(",", ppos); \ 2640 if (pos == Utf8Str::npos) \ 2641 { \ 2642 Log(( #res " extracting from %s is failed\n", str.raw())); \ 2643 continue; \ 2644 } \ 2645 res = str.substr(ppos, pos - ppos); \ 2646 Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \ 2647 ppos = pos + 1; \ 2648 }while (0) 2649 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos); 2650 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos); 2651 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos); 2652 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos); 2653 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos); 2654 strGuestPort = utf.substr(ppos, utf.length() - ppos); 2655 #undef ITERATE_TO_NEXT_TERM 2656 2657 uint32_t proto = strProto.toUInt32(); 2658 bool fValid = true; 2659 switch(proto) 2660 { 2661 case NATProtocol_UDP: 2662 strProto = "UDP"; 2663 break; 2664 case NATProtocol_TCP: 2665 strProto = "TCP"; 2666 break; 2667 default: 2668 fValid = false; 2669 } 2670 /* continue with next rule if no valid proto was passed */ 2671 if (!fValid) 2672 continue; 2673 2674 rc = CFGMR3InsertNode(pCfg, strName.raw(), &pPF); RC_CHECK(); 2675 rc = CFGMR3InsertString(pPF, "Protocol", strProto.raw()); RC_CHECK(); 2676 2677 if (!strHostIP.isEmpty()) 2678 { 2679 rc = CFGMR3InsertString(pPF, "BindIP", strHostIP.raw()); RC_CHECK(); 2680 } 2681 2682 if (!strGuestIP.isEmpty()) 2683 { 2684 rc = CFGMR3InsertString(pPF, "GuestIP", strGuestIP.raw()); RC_CHECK(); 2685 } 2686 2687 port = RTStrToUInt16(strHostPort.raw()); 2688 if (port) 2689 { 2690 rc = CFGMR3InsertInteger(pPF, "HostPort", port); RC_CHECK(); 2691 } 2692 2693 port = RTStrToUInt16(strGuestPort.raw()); 2694 if (port) 2695 { 2696 rc = CFGMR3InsertInteger(pPF, "GuestPort", port); RC_CHECK(); 2697 } 2698 } 2563 2699 break; 2564 2700 }
Note:
See TracChangeset
for help on using the changeset viewer.