VBoxNetBaseService.cpp revision a9749534ba173982f6c3bafe8d51ccd22960e493
/* $Id$ */
/** @file
* VBoxNetDHCP - DHCP Service for connecting to IntNet.
*/
/** @todo r=bird: Cut&Past rules... Please fix DHCP refs! */
/*
* Copyright (C) 2009-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_NET_SERVICE
#include <iprt/buildconfig.h>
#include <iprt/initterm.h>
#include <vector>
#include <string>
#include "VBoxNetLib.h"
#include "VBoxNetBaseService.h"
#ifdef RT_OS_WINDOWS /* WinMain */
# include <Windows.h>
# include <stdlib.h>
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
static RTGETOPTDEF g_aGetOptDef[] =
{
};
{
}
{
/*
* Close the interface connection.
*/
if (m_hIf != INTNET_HANDLE_INVALID)
{
}
if (m_pSession)
{
SUPR3Term(false /*fForced*/);
}
}
int VBoxNetBaseService::init()
{
/* numbers from DrvIntNet */
m_cVerbosity = 0;
m_Name = "VBoxNetNAT";
m_Network = "intnet";
for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
return VINF_SUCCESS;
}
/**
* Parse the arguments.
*
* @returns 0 on success, fully bitched exit code on failure.
*
* @param argc Argument count.
* @param argv Argument vector.
*/
{
Log2(("BaseService: parseArgs enter\n"));
for (;;)
{
if (!rc)
break;
switch (rc)
{
case 'N':
break;
case 'n':
break;
case 't':
break;
case 'T':
else
{
return 1;
}
break;
case 'a':
break;
case 'i':
break;
case 'v':
m_cVerbosity++;
break;
case 'V':
return 1;
case 'h':
RTPrintf("VBoxNetDHCP Version %s\n"
"All rights reserved.\n"
"\n"
"Usage: VBoxNetDHCP <options>\n"
"\n"
"Options:\n",
RTBldCfgVersion());
for (unsigned int i = 0; i < m_vecOptionDefs.size(); i++)
usage(); /* to print Service Specific usage */
return 1;
default:
if (RT_FAILURE(rc1))
{
RTPrintf("Use --help for more information.\n");
return rc;
}
}
}
return rc;
}
int VBoxNetBaseService::tryGoOnline(void)
{
/*
* Open the session, load ring-0 and issue the request.
*/
if (RT_FAILURE(rc))
{
return 1;
}
char szPath[RTPATH_MAX];
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Create the open request.
*/
/*
* Issue the request.
*/
if (RT_FAILURE(rc))
{
goto bad;
}
/*
* Get the ring-3 address of the shared interface buffer.
*/
rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS, 0, &GetBufferPtrsReq.Hdr);
if (RT_FAILURE(rc))
{
Log2(("VBoxNetBaseService: SUPR3CallVMMR0Ex(,VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS,) failed, rc=%Rrc\n", rc));
goto bad;
}
Log2(("pBuf=%p cbBuf=%d cbSend=%d cbRecv=%d\n",
/*
* Activate the interface.
*/
if (RT_SUCCESS(rc))
return 0;
/* bail out */
Log2(("VBoxNetBaseService: SUPR3CallVMMR0Ex(,VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE,) failed, rc=%Rrc\n", rc));
return 0;
bad:
return 1;
}
void VBoxNetBaseService::shutdown(void)
{
}
/**
* Print debug message depending on the m_cVerbosity level.
*
* @param iMinLevel The minimum m_cVerbosity level for this message.
* @param fMsg Whether to dump parts for the current DHCP message.
* @param pszFmt The message format string.
* @param ... Optional arguments.
*/
inline void VBoxNetBaseService::debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const
{
if (iMinLevel <= m_cVerbosity)
{
}
}
/**
* Print debug message depending on the m_cVerbosity level.
*
* @param iMinLevel The minimum m_cVerbosity level for this message.
* @param fMsg Whether to dump parts for the current DHCP message.
* @param pszFmt The message format string.
* @param va Optional arguments.
*/
void VBoxNetBaseService::debugPrintV(int iMinLevel, bool fMsg, const char *pszFmt, va_list va) const
{
if (iMinLevel <= m_cVerbosity)
{
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: %s: %N\n", iMinLevel >= 2 ? "debug" : "info", pszFmt, &vaCopy);
}
}
{
if (!pOptArray)
return NULL;
for (unsigned int i = 0; i < m_vecOptionDefs.size(); ++i)
{
}
return pOptArray;
}