VBoxNetDHCP.cpp revision 2883e7039d8138676e0a0d96c56f4838f1bf049b
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * VBoxNetDHCP - DHCP Service for connecting to IntNet.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Copyright (C) 2009-2011 Oracle Corporation
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * available from http://www.virtualbox.org. This file is free software;
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * General Public License (GPL) as published by the Free Software
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync/** @page pg_net_dhcp VBoxNetDHCP
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync * Write a few words...
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync/*******************************************************************************
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync* Header Files *
a3f3701cea1ba388e7c877955252bb7375eedebdvboxsync*******************************************************************************/
#include "../NetLib/VBoxNetLib.h"
#include "../NetLib/shared_ptr.h"
#include <vector>
#include <list>
#include <string>
#include <map>
#include "../NetLib/VBoxNetBaseService.h"
# include <Windows.h>
# include <stdlib.h>
# ifdef INET_ADDRSTRLEN
/* On Windows INET_ADDRSTRLEN defined as 22 Ws2ipdef.h, because it include port number */
#include "Config.h"
VBoxNetDhcp();
virtual ~VBoxNetDhcp();
int init();
void done();
int initNoMain();
int initWithMain();
int fetchAndUpdateDnsInfo();
char Key;
} CMDLNPRM;
static inline int configGetBoundryAddress(const ComDhcpServerPtr& dhcp, bool fUpperBoundry, RTNETADDRIPV4& boundryAddress)
if (fUpperBoundry)
m_cbCurMsg = 0;
m_fIgnoreCmdLineParameters = true;
m_fIgnoreCmdLineParameters = false;
switch (rc)
return rc;
return VINF_SUCCESS;
if (isMainNeeded())
return VINF_SUCCESS;
VBoxNetALock(this);
debugPrint(1, true, "VBoxNetDHCP: Skipping invalid DHCP packet.\n"); /** @todo handle pure bootp clients too? */
m_cbCurMsg = 0;
return VINF_SUCCESS;
switch (uMsgType)
case RTNET_DHCP_MT_DISCOVER:
case RTNET_DHCP_MT_REQUEST:
case RTNET_DHCP_MT_DECLINE:
case RTNET_DHCP_MT_RELEASE:
case RTNET_DHCP_MT_INFORM:
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: %s: %N\n", iMinLevel >= 2 ? "debug" : "info", pszFmt, &vaCopy);
if ( fMsg
&& m_pCurMsg)
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: debug: %8s chaddr=%.6Rhxs ciaddr=%d.%d.%d.%d yiaddr=%d.%d.%d.%d siaddr=%d.%d.%d.%d xid=%#x\n",
m_pCurMsg->bp_ciaddr.au8[0], m_pCurMsg->bp_ciaddr.au8[1], m_pCurMsg->bp_ciaddr.au8[2], m_pCurMsg->bp_ciaddr.au8[3],
m_pCurMsg->bp_yiaddr.au8[0], m_pCurMsg->bp_yiaddr.au8[1], m_pCurMsg->bp_yiaddr.au8[2], m_pCurMsg->bp_yiaddr.au8[3],
m_pCurMsg->bp_siaddr.au8[0], m_pCurMsg->bp_siaddr.au8[1], m_pCurMsg->bp_siaddr.au8[2], m_pCurMsg->bp_siaddr.au8[3],
switch (uMsgType)
return VINF_SUCCESS;
if (!fNeedDhcpServer)
return VERR_CANCELLED;
return VINF_SUCCESS;
VBoxNetALock(this);
return VINF_SUCCESS;
switch(aEventType)
if (!fStart)
shutdown();
shutdown();
return S_OK;
if (!pDhcp)
if (rc)
return rc;
delete pDhcp;
delete pDhcp;
#ifndef VBOX_WITH_HARDENING
# ifdef RT_OS_WINDOWS
PostQuitMessage(0);
bool bExit = false;
if (atomWindowClass != 0)
if (hwnd)
bExit = true;
if(bExit)
/* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */
exit(0);