Exemple #1
0
/**
 *  Entry point.
 */
extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv)
{
    /*
     * Instantiate the DHCP server and hand it the options.
     */

    VBoxNetDhcp *pDhcp = new VBoxNetDhcp();
    if (!pDhcp)
    {
        RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: new VBoxNetDhcp failed!\n");
        return 1;
    }
    int rc = pDhcp->parseArgs(argc - 1, argv + 1);
    if (rc)
        return rc;

    pDhcp->init();

    /*
     * Try connect the server to the network.
     */
    rc = pDhcp->tryGoOnline();
    if (RT_FAILURE(rc))
    {
        delete pDhcp;
        return 1;
    }

    /*
     * Process requests.
     */
    g_pDhcp = pDhcp;
    rc = pDhcp->run();
    g_pDhcp = NULL;
    delete pDhcp;

    return 0;
}
/**
 *  Entry point.
 */
extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv)
{
    /*
     * Instantiate the DHCP server and hand it the options.
     */
    VBoxNetDhcp *pDhcp = new VBoxNetDhcp();
    if (!pDhcp)
    {
        RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: new VBoxNetDhcp failed!\n");
        return 1;
    }

    RTEXITCODE rcExit = (RTEXITCODE)pDhcp->parseArgs(argc - 1, argv + 1);
    if (rcExit != RTEXITCODE_SUCCESS)
        return rcExit;

#ifdef RT_OS_WINDOWS
    /* DIFx hack. */
    RTTHREAD hMakeUseKillableThread = NIL_RTTHREAD;
    int rc2 = RTThreadCreate(&hMakeUseKillableThread, DIFxKillableProcessThreadProc, NULL, 0,
                             RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "DIFxKill");
    if (RT_FAILURE(rc2))
        hMakeUseKillableThread = NIL_RTTHREAD;
#endif

    pDhcp->init();

    /*
     * Try connect the server to the network.
     */
    int rc = pDhcp->tryGoOnline();
    if (RT_SUCCESS(rc))
    {
        /*
         * Process requests.
         */
        g_pDhcp = pDhcp;
        rc = pDhcp->run();
        pDhcp->done();

        g_pDhcp = NULL;
    }
    delete pDhcp;

#ifdef RT_OS_WINDOWS
    /* Kill DIFx hack. */
    if (hMakeUseKillableThread != NIL_RTTHREAD)
    {
        g_fExitProcessOnQuit = false;
        PostThreadMessage((DWORD)RTThreadGetNative(hMakeUseKillableThread), WM_QUIT, 0, 0);
        RTThreadWait(hMakeUseKillableThread, RT_MS_1SEC * 5U, NULL);
    }
#endif

    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
}