VirtualBox

Changeset 49516 in vbox for trunk/src/VBox/NetworkServices


Ignore:
Timestamp:
Nov 16, 2013 6:42:31 AM (11 years ago)
Author:
vboxsync
Message:

Introduce option "--need-main(-M) on|off" in network services to emphosize whether network service need to establish connection with Main (by default this optiois off).

Location:
trunk/src/VBox/NetworkServices
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp

    r49490 r49516  
    357357int VBoxNetDhcp::init()
    358358{
    359     HRESULT hrc = S_OK;
    360     /* ok, here we should initiate instance of dhcp server
    361      * and listener for Dhcp configuration events
    362      */
    363     AssertRCReturn(virtualbox.isNull(), VERR_INTERNAL_ERROR);
    364 
    365     hrc = virtualbox->FindDHCPServerByNetworkName(com::Bstr(m_Network.c_str()).raw(),
    366                                                   m_DhcpServer.asOutParam());
    367     AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
    368 
    369     hrc = virtualbox->FindNATNetworkByName(com::Bstr(m_Network.c_str()).raw(),
    370                                            m_NATNetwork.asOutParam());
    371 
    372 
    373     bool fNoMain = m_NATNetwork.isNull();
    374     int rc;
     359    int rc = this->VBoxNetBaseService::init();
     360    AssertRCReturn(rc, rc);
     361
    375362    NetworkManager *netManager = NetworkManager::getNetworkManager();
    376363
     
    378365    netManager->setOurNetmask(m_Ipv4Netmask);
    379366    netManager->setOurMac(m_MacAddress);
    380 
    381     if (fNoMain)
     367   
     368    if (m_fNeedMain)
     369        rc = initWithMain();
     370    else
    382371        rc = initNoMain();
    383     else
    384         rc = initWithMain();
    385372
    386373    AssertRCReturn(rc, rc);
     
    733720int VBoxNetDhcp::initNoMain()
    734721{
    735     /* In Host-Only mode we don't need Main. */
    736     com::Shutdown();
    737 
    738722    CmdParameterIterator it;
    739723
     
    777761int VBoxNetDhcp::initWithMain()
    778762{
     763    /* ok, here we should initiate instance of dhcp server
     764     * and listener for Dhcp configuration events
     765     */
     766    AssertRCReturn(virtualbox.isNull(), VERR_INTERNAL_ERROR);
     767
     768    HRESULT hrc = virtualbox->FindDHCPServerByNetworkName(com::Bstr(m_Network.c_str()).raw(),
     769                                                  m_DhcpServer.asOutParam());
     770    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
     771
     772    hrc = virtualbox->FindNATNetworkByName(com::Bstr(m_Network.c_str()).raw(),
     773                                           m_NATNetwork.asOutParam());
     774
    779775    BOOL fNeedDhcpServer = false;
    780776    if (FAILED(m_NATNetwork->COMGETTER(NeedDhcpServer)(&fNeedDhcpServer)))
     
    787783    com::Bstr strGateway;
    788784
    789     HRESULT hrc = m_NATNetwork->COMGETTER(Gateway)(strGateway.asOutParam());
     785    hrc = m_NATNetwork->COMGETTER(Gateway)(strGateway.asOutParam());
    790786    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
    791787    RTNetStrToIPv4Addr(com::Utf8Str(strGateway).c_str(), &gateway);
     
    918914     * Instantiate the DHCP server and hand it the options.
    919915     */
    920     HRESULT hrc = com::Initialize();
    921     Assert(!FAILED(hrc));
    922916
    923917    VBoxNetDhcp *pDhcp = new VBoxNetDhcp();
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp

    r49413 r49516  
    890890int VBoxNetLwipNAT::init()
    891891{
    892     int rc = VINF_SUCCESS;
    893892    HRESULT hrc;
    894893    LogFlowFuncEnter();
     
    896895
    897896    /* virtualbox initialized in super class */
     897
     898    int rc = ::VBoxNetBaseService::init();
     899    AssertRCReturn(rc, rc);
    898900
    899901    hrc = virtualbox->FindNATNetworkByName(com::Bstr(m_Network.c_str()).raw(),
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp

    r49492 r49516  
    8686    { "--netmask",        'm',   RTGETOPT_REQ_IPV4ADDR },
    8787    { "--verbose",        'v',   RTGETOPT_REQ_NOTHING },
     88    { "--need-main",      'M',   RTGETOPT_REQ_BOOL },
    8889};
    8990
     
    102103    m_Name                  = "VBoxNetNAT";
    103104    m_Network               = "intnet";
     105    m_fNeedMain             = false;
    104106
    105107    for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
    106108        m_vecOptionDefs.push_back(&g_aGetOptDef[i]);
    107 
    108     HRESULT hrc = virtualbox.createLocalObject(CLSID_VirtualBox);
    109     if (FAILED(hrc))
    110         RTMsgError("Failed to create the VirtualBox object!");
    111109}
    112110
     
    140138int VBoxNetBaseService::init()
    141139{
     140    if (m_fNeedMain)
     141    {
     142        HRESULT hrc = com::Initialize();
     143        AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
     144
     145        hrc = virtualbox.createLocalObject(CLSID_VirtualBox);
     146        AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
     147    }
     148
    142149    return VINF_SUCCESS;
    143150}
     
    223230                return 1;
    224231
     232            case 'M': // --need-main
     233                m_fNeedMain = true;
     234                break;
     235
    225236            case 'h': // --help (missed)
    226237                RTPrintf("%s Version %sr%u\n"
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h

    r47019 r49516  
    8383    PINTNETBUF          m_pIfBuf;       /**< Interface buffer. */
    8484    std::vector<PRTGETOPTDEF> m_vecOptionDefs;
     85    bool                m_fNeedMain;
    8586    /** @} */
    8687    /** @name Debug stuff
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette