Index: /trunk/Config.kmk
===================================================================
--- /trunk/Config.kmk	(revision 75613)
+++ /trunk/Config.kmk	(revision 75614)
@@ -771,4 +771,6 @@
  VBOX_WITH_VDE = 1
 endif
+# Use new VBoxNetDhcpd instead of old VBoxNetDHCP
+VBOX_WITH_DHCPD = 1
 ## @}
 
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDHCPServer.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDHCPServer.cpp	(revision 75613)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDHCPServer.cpp	(revision 75614)
@@ -52,5 +52,6 @@
     OP_ADD = 1000,
     OP_REMOVE,
-    OP_MODIFY
+    OP_MODIFY,
+    OP_RESTART
 } OPCODE;
 
@@ -319,4 +320,5 @@
 
     if(   enmCode != OP_REMOVE
+       && enmCode != OP_RESTART
        && GlobalDhcpOptions.empty()
        && VmSlot2Options.empty())
@@ -374,5 +376,17 @@
     }
 
-    if(enmCode != OP_REMOVE)
+    if (enmCode == OP_RESTART)
+    {
+        CHECK_ERROR(svr, Restart());
+        if(FAILED(rc))
+            return errorArgument("Failed to restart server");
+    }
+    else if (enmCode == OP_REMOVE)
+    {
+        CHECK_ERROR(a->virtualBox, RemoveDHCPServer(svr));
+        if(FAILED(rc))
+            return errorArgument("Failed to remove server");
+    }
+    else
     {
         if (pIp || pNetmask || pLowerIp || pUpperIp)
@@ -425,10 +439,4 @@
         }
     }
-    else
-    {
-        CHECK_ERROR(a->virtualBox, RemoveDHCPServer(svr));
-        if(FAILED(rc))
-            return errorArgument("Failed to remove server");
-    }
 
     return RTEXITCODE_SUCCESS;
@@ -448,4 +456,6 @@
     else if (strcmp(a->argv[0], "remove") == 0)
         rcExit = handleOp(a, OP_REMOVE, 1);
+    else if (strcmp(a->argv[0], "restart") == 0)
+        rcExit = handleOp(a, OP_RESTART, 1);
     else
         rcExit = errorSyntax(USAGE_DHCPSERVER, "Invalid parameter '%s'", Utf8Str(a->argv[0]).c_str());
Index: /trunk/src/VBox/Main/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Main/Makefile.kmk	(revision 75613)
+++ /trunk/src/VBox/Main/Makefile.kmk	(revision 75614)
@@ -79,4 +79,5 @@
 	$(if $(VBOX_WITH_HGCM),VBOX_WITH_HGCM,) \
 	$(if $(VBOX_WITH_HOSTNETIF_API),VBOX_WITH_HOSTNETIF_API,) \
+	$(if $(VBOX_WITH_DHCPD),VBOX_WITH_DHCPD,) \
 	$(if $(VBOX_WITH_LIVE_MIGRATION),VBOX_WITH_LIVE_MIGRATION,) \
 	$(if $(VBOX_WITH_MIDL_PROXY_STUB),VBOX_WITH_MIDL_PROXY_STUB,) \
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 75613)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 75614)
@@ -1791,5 +1791,5 @@
   <interface
     name="IDHCPServer" extends="$unknown"
-    uuid="00c8f974-92c5-44a1-8f3f-702469fdd04b"
+    uuid="197717d2-a742-4966-a529-d1467e903feb"
     wsmap="managed"
     reservedMethods="2" reservedAttributes="6"
@@ -1953,4 +1953,13 @@
         <result name="E_FAIL">
           Failed to stop the process.
+        </result>
+      </desc>
+    </method>
+
+    <method name="restart">
+      <desc>
+        Restart running DHCP server process.
+        <result name="E_FAIL">
+          Failed to restart the process.
         </result>
       </desc>
Index: /trunk/src/VBox/Main/include/DHCPServerImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/DHCPServerImpl.h	(revision 75613)
+++ /trunk/src/VBox/Main/include/DHCPServerImpl.h	(revision 75614)
@@ -50,4 +50,5 @@
     static const std::string kDsrKeyLowerIp;
     static const std::string kDsrKeyUpperIp;
+    static const std::string kDsrKeyConfig;
 };
 
@@ -125,4 +126,5 @@
                   const com::Utf8Str &aTrunkType);
     HRESULT stop();
+    HRESULT restart();
 
     struct Data;
Index: /trunk/src/VBox/Main/include/NetworkServiceRunner.h
===================================================================
--- /trunk/src/VBox/Main/include/NetworkServiceRunner.h	(revision 75613)
+++ /trunk/src/VBox/Main/include/NetworkServiceRunner.h	(revision 75614)
@@ -36,4 +36,5 @@
 
     int setOption(const std::string& key, const std::string& val);
+    void clearOptions();
 
     int  start(bool aKillProcOnStop);
Index: /trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp	(revision 75613)
+++ /trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp	(revision 75614)
@@ -25,6 +25,9 @@
 
 #include <iprt/asm.h>
+#include <iprt/file.h>
 #include <iprt/net.h>
+#include <iprt/path.h>
 #include <iprt/cpp/utils.h>
+#include <iprt/cpp/xml.h>
 
 #include <VBox/com/array.h>
@@ -38,4 +41,5 @@
 const std::string DHCPServerRunner::kDsrKeyLowerIp = "--lower-ip";
 const std::string DHCPServerRunner::kDsrKeyUpperIp = "--upper-ip";
+const std::string DHCPServerRunner::kDsrKeyConfig  = "--config";
 
 
@@ -45,5 +49,7 @@
         : enabled(FALSE)
         , router(false)
-    {}
+    {
+        tempConfigFileName[0] = '\0';
+    }
 
     Utf8Str IPAddress;
@@ -57,4 +63,9 @@
     settings::DhcpOptionMap GlobalDhcpOptions;
     settings::VmSlot2OptionsMap VmSlot2Options;
+
+    char tempConfigFileName[RTPATH_MAX];
+    com::Utf8Str networkName;
+    com::Utf8Str trunkName;
+    com::Utf8Str trunkType;
 };
 
@@ -98,4 +109,7 @@
     if (autoUninitSpan.uninitDone())
         return;
+
+    if (m->dhcp.isRunning())
+        stop();
 
     unconst(mVirtualBox) = NULL;
@@ -599,4 +613,28 @@
 
 
+DECLINLINE(void) addOptionChild(xml::ElementNode *pParent, uint32_t OptCode, const settings::DhcpOptValue &OptValue)
+{
+    xml::ElementNode *pOption = pParent->createChild("Option");
+    pOption->setAttribute("name", OptCode);
+    pOption->setAttribute("encoding", OptValue.encoding);
+    pOption->setAttribute("value", OptValue.text.c_str());
+}
+
+
+HRESULT DHCPServer::restart()
+{
+    if (!m->dhcp.isRunning())
+        return E_FAIL;
+    /*
+        * Disabled servers will be brought down, but won't be restarted.
+        * (see DHCPServer::start)
+        */
+    HRESULT hrc = stop();
+    if (SUCCEEDED(hrc))
+        hrc = start(m->networkName, m->trunkName, m->trunkType);
+    return hrc;
+}
+
+
 HRESULT DHCPServer::start(const com::Utf8Str &aNetworkName,
                           const com::Utf8Str &aTrunkName,
@@ -607,4 +645,105 @@
         return S_OK;
 
+    /*
+     * @todo: the existing code cannot handle concurrent attempts to start DHCP server.
+     * Note that technically it may receive different parameters from different callers.
+     */
+    m->networkName = aNetworkName;
+    m->trunkName = aTrunkName;
+    m->trunkType = aTrunkType;
+
+    m->dhcp.clearOptions();
+#ifdef VBOX_WITH_DHCPD
+    int rc = RTPathTemp(m->tempConfigFileName, sizeof(m->tempConfigFileName));
+    if (RT_FAILURE(rc))
+        return E_FAIL;
+    rc = RTPathAppend(m->tempConfigFileName, sizeof(m->tempConfigFileName), "dhcp-config-XXXXX.xml");
+    if (RT_FAILURE(rc))
+    {
+        m->tempConfigFileName[0] = '\0';
+        return E_FAIL;
+    }
+    rc = RTFileCreateTemp(m->tempConfigFileName, 0600);
+    if (RT_FAILURE(rc))
+    {
+        m->tempConfigFileName[0] = '\0';
+        return E_FAIL;
+    }
+
+    xml::Document doc;
+    xml::ElementNode *pElmRoot = doc.createRootElement("DHCPServer");
+    pElmRoot->setAttribute("networkName", m->networkName.c_str());
+    if (!m->trunkName.isEmpty())
+        pElmRoot->setAttribute("trunkName", m->trunkName.c_str());
+    pElmRoot->setAttribute("trunkType", m->trunkType.c_str());
+    pElmRoot->setAttribute("IPAddress",  Utf8Str(m->IPAddress).c_str());
+    pElmRoot->setAttribute("networkMask", Utf8Str(m->GlobalDhcpOptions[DhcpOpt_SubnetMask].text).c_str());
+    pElmRoot->setAttribute("lowerIP", Utf8Str(m->lowerIP).c_str());
+    pElmRoot->setAttribute("upperIP", Utf8Str(m->upperIP).c_str());
+
+    /* Process global options */
+    xml::ElementNode *pOptions = pElmRoot->createChild("Options");
+    // settings::DhcpOptionMap::const_iterator itGlobal;
+    for (settings::DhcpOptionMap::const_iterator it = m->GlobalDhcpOptions.begin();
+         it != m->GlobalDhcpOptions.end();
+         ++it)
+        addOptionChild(pOptions, (*it).first, (*it).second);
+
+    /* Process network-adapter-specific options */
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+    HRESULT hrc = S_OK;
+    ComPtr<IMachine> machine;
+    ComPtr<INetworkAdapter> nic;
+    settings::VmSlot2OptionsIterator it;
+    for(it = m->VmSlot2Options.begin(); it != m->VmSlot2Options.end(); ++it)
+    {
+        alock.release();
+        hrc = mVirtualBox->FindMachine(Bstr(it->first.VmName).raw(), machine.asOutParam());
+        alock.acquire();
+
+        if (FAILED(hrc))
+            continue;
+
+        alock.release();
+        hrc = machine->GetNetworkAdapter(it->first.Slot, nic.asOutParam());
+        alock.acquire();
+
+        if (FAILED(hrc))
+            continue;
+
+        com::Bstr mac;
+
+        alock.release();
+        hrc = nic->COMGETTER(MACAddress)(mac.asOutParam());
+        alock.acquire();
+
+        if (FAILED(hrc)) /* no MAC address ??? */
+            continue;
+
+        /* Convert MAC address from XXXXXXXXXXXX to XX:XX:XX:XX:XX:XX */
+        Utf8Str strMacWithoutColons(mac);
+        const char *pszSrc = strMacWithoutColons.c_str();
+        RTMAC binaryMac;
+        if (RTStrConvertHexBytes(pszSrc, &binaryMac, sizeof(binaryMac), 0) != VINF_SUCCESS)
+            continue;
+        char szMac[18]; /* "XX:XX:XX:XX:XX:XX" */
+        if (RTStrPrintHexBytes(szMac, sizeof(szMac), &binaryMac, sizeof(binaryMac), RTSTRPRINTHEXBYTES_F_SEP_COLON) != VINF_SUCCESS)
+            continue;
+
+        xml::ElementNode *pMacConfig = pElmRoot->createChild("Config");
+        pMacConfig->setAttribute("MACAddress", szMac);
+
+        com::Utf8Str encodedOption;
+        settings::DhcpOptionMap &map = i_findOptMapByVmNameSlot(it->first.VmName, it->first.Slot);
+        settings::DhcpOptionMap::const_iterator itAdapterOption;
+        for (itAdapterOption = map.begin(); itAdapterOption != map.end(); ++itAdapterOption)
+            addOptionChild(pMacConfig, (*itAdapterOption).first, (*itAdapterOption).second);
+    }
+
+    xml::XmlFileWriter writer(doc);
+    writer.write(m->tempConfigFileName, true);
+
+    m->dhcp.setOption(DHCPServerRunner::kDsrKeyConfig, m->tempConfigFileName);
+#else /* !VBOX_WITH_DHCPD */
     /* Commmon Network Settings */
     m->dhcp.setOption(NetworkServiceRunner::kNsrKeyNetwork, aNetworkName.c_str());
@@ -628,4 +767,5 @@
     m->dhcp.setOption(DHCPServerRunner::kDsrKeyLowerIp, Utf8Str(m->lowerIP).c_str());
     m->dhcp.setOption(DHCPServerRunner::kDsrKeyUpperIp, Utf8Str(m->upperIP).c_str());
+#endif /* !VBOX_WITH_DHCPD */
 
     /* XXX: This parameters Dhcp Server will fetch via API */
@@ -637,4 +777,11 @@
 HRESULT DHCPServer::stop (void)
 {
+#ifdef VBOX_WITH_DHCPD
+    if (m->tempConfigFileName[0])
+    {
+        RTFileDelete(m->tempConfigFileName);
+        m->tempConfigFileName[0] = 0;
+    }
+#endif /* VBOX_WITH_DHCPD */
     return RT_FAILURE(m->dhcp.stop()) ? E_FAIL : S_OK;
 }
Index: /trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp	(revision 75613)
+++ /trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp	(revision 75614)
@@ -66,4 +66,10 @@
     m->mOptions.insert(std::map<std::string, std::string>::value_type(key, val));
     return VINF_SUCCESS;
+}
+
+
+void NetworkServiceRunner::clearOptions()
+{
+    m->mOptions.clear();
 }
 
Index: /trunk/src/VBox/NetworkServices/Dhcpd/ClientId.h
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/ClientId.h	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/ClientId.h	(revision 75614)
@@ -35,6 +35,6 @@
     ClientId()
       : m_mac(), m_id() {}
-    ClientId(const RTMAC &mac, const OptClientId &id)
-      : m_mac(mac), m_id(id) {}
+    ClientId(const RTMAC &macParam, const OptClientId &idParam)
+      : m_mac(macParam), m_id(idParam) {}
 
     const RTMAC &mac() const { return m_mac; }
Index: /trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp	(revision 75614)
@@ -589,6 +589,6 @@
     /** @todo r=bird: Visual C++ 2010 does not grok this use of 'auto'. */
     // XXX: debug
-    for (auto it: m_GlobalOptions) {
-        std::shared_ptr<DhcpOption> opt(it.second);
+    for (optmap_t::const_iterator it = m_GlobalOptions.begin(); it != m_GlobalOptions.end(); ++it) {
+        std::shared_ptr<DhcpOption> opt(it->second);
 
         octets_t data;
@@ -596,5 +596,6 @@
 
         bool space = false;
-        for (auto c: data) {
+        for (octets_t::const_iterator itData = data.begin(); itData != data.end(); ++itData) {
+            uint8_t c = *itData;
             if (space)
                 std::cout << " ";
@@ -854,6 +855,8 @@
     optmap << new OptSubnetMask(m_IPv4Netmask);
 
-    for (auto optreq: reqOpts.value())
-    {
+    const OptParameterRequest::value_t& reqValue = reqOpts.value();
+    for (octets_t::const_iterator itOptReq = reqValue.begin(); itOptReq != reqValue.end(); ++itOptReq)
+    {
+        uint8_t optreq = *itOptReq;
         std::cout << ">>> requested option " << (int)optreq << std::endl;
 
@@ -890,6 +893,6 @@
     if (vmopts != NULL)
     {
-        for (auto it: *vmopts) {
-            std::shared_ptr<DhcpOption> opt(it.second);
+        for (optmap_t::const_iterator it = vmopts->begin(); it != vmopts->end(); ++it) {
+            std::shared_ptr<DhcpOption> opt(it->second);
             if (optmap.count(opt->optcode()) == 0 && opt->optcode() > 127)
             {
@@ -900,6 +903,6 @@
     }
 
-    for (auto it: m_GlobalOptions) {
-        std::shared_ptr<DhcpOption> opt(it.second);
+    for (optmap_t::const_iterator it = m_GlobalOptions.begin(); it != m_GlobalOptions.end(); ++it) {
+        std::shared_ptr<DhcpOption> opt(it->second);
         if (optmap.count(opt->optcode()) == 0 && opt->optcode() > 127)
         {
Index: /trunk/src/VBox/NetworkServices/Dhcpd/Db.h
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/Db.h	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/Db.h	(revision 75614)
@@ -51,10 +51,10 @@
     Binding(const Binding &);
 
-    explicit Binding(RTNETADDRIPV4 addr)
-      : m_addr(addr), m_state(FREE),
+    explicit Binding(RTNETADDRIPV4 addrParam)
+      : m_addr(addrParam), m_state(FREE),
         m_issued(), m_secLease() {}
 
-    Binding(RTNETADDRIPV4 addr, const ClientId &id)
-      : m_addr(addr), m_state(FREE), m_id(id),
+    Binding(RTNETADDRIPV4 addrParam, const ClientId &idParam)
+      : m_addr(addrParam), m_state(FREE), m_id(idParam),
         m_issued(), m_secLease() {}
 
@@ -70,7 +70,7 @@
     TimeStamp issued() const { return m_issued; }
 
-    Binding &setState(State state)
+    Binding &setState(State stateParam)
     {
-        m_state = state;
+        m_state = stateParam;
         return *this;
     }
@@ -85,7 +85,7 @@
     }
 
-    Binding &giveTo(const ClientId &id)
+    Binding &giveTo(const ClientId &idParam)
     {
-        m_id = id;
+        m_id = idParam;
         m_state = FREE;
         return *this;
Index: /trunk/src/VBox/NetworkServices/Dhcpd/Defs.h
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/Defs.h	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/Defs.h	(revision 75614)
@@ -24,6 +24,17 @@
 
 #include <map>
+#include <vector>
+
+#if __cplusplus >= 199711
 #include <memory>
-#include <vector>
+using std::shared_ptr;
+#else
+#include <tr1/memory>
+using std::tr1::shared_ptr;
+#endif
+
+#ifdef _MSC_VER
+# define __func__ __FUNCTION__
+#endif
 
 typedef std::vector<uint8_t> octets_t;
@@ -32,5 +43,5 @@
 
 class DhcpOption;
-typedef std::map<uint8_t, std::shared_ptr<DhcpOption>> optmap_t;
+typedef std::map<uint8_t, std::shared_ptr<DhcpOption> > optmap_t;
 
 inline bool operator==(const RTMAC &l, const RTMAC &r)
Index: /trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.cpp	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.cpp	(revision 75614)
@@ -323,5 +323,5 @@
 
 DhcpServerMessage::DhcpServerMessage(const DhcpClientMessage &req,
-                                     uint8_t messageType, RTNETADDRIPV4 serverAddr)
+                                     uint8_t messageTypeParam, RTNETADDRIPV4 serverAddr)
   : DhcpMessage(),
     m_optServerId(serverAddr)
@@ -329,5 +329,5 @@
     m_dst.u = 0xffffffff;       /* broadcast */
 
-    m_optMessageType = OptMessageType(messageType);
+    m_optMessageType = OptMessageType(messageTypeParam);
 
     /* copy values from the request (cf. RFC2131 Table 3) */
Index: /trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.cpp	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.cpp	(revision 75614)
@@ -36,5 +36,5 @@
 optmap_t &operator<<(optmap_t &optmap, const std::shared_ptr<DhcpOption> &option)
 {
-    if (option == NULL)
+    if (!option)
         return optmap;
 
Index: /trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.h
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.h	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.h	(revision 75614)
@@ -342,5 +342,5 @@
     static OptValue *parse(const char *pcszValue)
     {
-        value_t v;
+        typename OptValueBase<T>::value_t v;
         int rc = DhcpOption::parse1(v, pcszValue);
         if (RT_FAILURE(rc))
@@ -544,5 +544,5 @@
     static OptList *parse(const char *pcszValue)
     {
-        value_t v;
+        typename OptListBase<T>::value_t v;
         int rc = DhcpOption::parseList(v, pcszValue);
         if (RT_FAILURE(rc) || v.empty())
Index: /trunk/src/VBox/NetworkServices/Dhcpd/Makefile.kmk
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/Makefile.kmk	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/Makefile.kmk	(revision 75614)
@@ -29,39 +29,49 @@
  ifdef VBOX_WITH_HARDENING
   PROGRAMS += VBoxNetDhcpdHardened
-  VBoxNetDhcpdHardened_TEMPLATE = VBOXR3HARDENEDEXE
-  VBoxNetDhcpdHardened_NAME     = VBoxNetDhcpd
-  VBoxNetDhcpdHardened_DEFS     = SERVICE_NAME=\"VBoxNetDhcpd\"
-  VBoxNetDhcpdHardened_SOURCES  = VBoxNetDhcpdHardened.cpp
-  VBoxNetDhcpdHardened_SOURCES.win = $(VBoxNetLwipNAT_0_OUTDIR)/VBoxNetDhcpd-icon.rc
-  VBoxNetDhcpdHardened_LDFLAGS.win = /SUBSYSTEM:windows
+  DLLS += VBoxNetDhcpd
  else
   PROGRAMS += VBoxNetDhcpd
  endif
 
- VBoxNetDhcpd_TEMPLATE := $(if-expr defined(VBOX_WITH_HARDENING),VBOXMAINDLL,VBOXMAINCLIENTEXE)
- VBoxNetDhcpd_NAME     := VBoxNetDhcpd
+ VBoxNetDhcpdHardened_TEMPLATE = VBOXR3HARDENEDEXE
+ VBoxNetDhcpdHardened_NAME     = VBoxNetDHCP
+ VBoxNetDhcpdHardened_DEFS     = SERVICE_NAME=\"VBoxNetDhcpd\"
+ VBoxNetDhcpdHardened_SOURCES  = VBoxNetDhcpdHardened.cpp
+ VBoxNetDhcpdHardened_SOURCES.win = $(VBoxNetDhcpd_0_OUTDIR)/VBoxNetDhcpd-icon.rc
+ VBoxNetDhcpdHardened_LDFLAGS.win = /SUBSYSTEM:windows
+
+ VBoxNetDhcpd_TEMPLATE := $(if-expr defined(VBOX_WITH_HARDENING),VBoxR3Dll,VBOXR3EXE)
+ VBoxNetDhcpd_NAME      = VBoxNetDHCP
  # VBoxNetDhcpd_DEFS      = IPv6
- # VBoxNetLwipNAT_DEFS.linux = WITH_VALGRIND
- VBoxNetDhcpd_DEFS.win  = VBOX_COM_OUTOFPROC_MODULE _WIN32_WINNT=0x501 # Windows XP
+ # VBoxNetDhcpd_DEFS.linux = WITH_VALGRIND
+ #VBoxNetDhcpd_DEFS.win  = VBOX_COM_OUTOFPROC_MODULE _WIN32_WINNT=0x501 # Windows XP
 
  # (current dir is for for lwipopts.h)
  VBoxNetDhcpd_INCS += . $(addprefix ../../Devices/Network/lwip-new/,$(LWIP_INCS))
 
- VBoxNetDhcpd_SOURCES  =
- VBoxNetDhcpd_SOURCES += ClientId.cpp
- VBoxNetDhcpd_SOURCES += Config.cpp
- VBoxNetDhcpd_SOURCES += DHCPD.cpp
- VBoxNetDhcpd_SOURCES += Db.cpp
- VBoxNetDhcpd_SOURCES += DhcpMessage.cpp
- VBoxNetDhcpd_SOURCES += DhcpOptions.cpp
- VBoxNetDhcpd_SOURCES += IPv4Pool.cpp
- VBoxNetDhcpd_SOURCES += TimeStamp.cpp
- VBoxNetDhcpd_SOURCES += VBoxNetDhcpd.cpp
- VBoxNetDhcpd_SOURCES += $(addprefix ../../Devices/Network/lwip-new/,$(LWIP_SOURCES))
+ VBoxNetDhcpd_DEFS    = KBUILD_TYPE=\"$(KBUILD_TYPE)\"
+ ifneq ($(KBUILD_TARGET),win)
+  VBoxNetDhcpd_DEFS     += VBOX_WITH_XPCOM
+  VBoxNetDhcpd_INCS     += $(VBOX_XPCOM_INCS)
+  # We want -std=c++11 for 4.7 and newer compilers, and -std=c++0x for older ones.
+  VBoxNetDhcpd_CXXFLAGS += -std=$(if $(VBOX_GCC_VERSION_CXX),$(if $(VBOX_GCC_VERSION_CXX) < 40700,c++0x,c++11),c++0x)
+ endif
+ VBoxNetDhcpd_SOURCES = ../../Main/glue/VBoxLogRelCreate.cpp \
+                        ../../Main/glue/GetVBoxUserHomeDirectory.cpp \
+                        ClientId.cpp \
+                        Config.cpp \
+                        DHCPD.cpp \
+                        Db.cpp \
+                        DhcpMessage.cpp \
+                        DhcpOptions.cpp \
+                        IPv4Pool.cpp \
+                        TimeStamp.cpp \
+                        VBoxNetDhcpd.cpp \
+                        $(addprefix ../../Devices/Network/lwip-new/,$(LWIP_SOURCES))
 
- VBoxNetLwipNAT_LIBS = $(LIB_RUNTIME)
+ VBoxNetDhcpd_LIBS = $(LIB_RUNTIME)
 
- VBoxNetLwipNAT_LIBS.solaris += socket nsl
- VBoxNetLwipNAT_LDFLAGS.win = /SUBSYSTEM:windows
+ VBoxNetDhcpd_LIBS.solaris += socket nsl
+ VBoxNetDhcpd_LDFLAGS.win = /SUBSYSTEM:windows
 
  ifeq ($(KBUILD_TARGET),win)
Index: /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp	(revision 75614)
@@ -448,5 +448,5 @@
                                                      i, cSegs,
                                                      &cbSegFrame);
-                ifInput(pvSegFrame, cbFrame);
+                ifInput(pvSegFrame, (uint32_t)cbFrame);
             }
         }
@@ -738,8 +738,8 @@
 
     unique_ptr_pbuf q ( pbuf_alloc(PBUF_RAW, (u16_t)data.size(), PBUF_RAM) );
-    if (q == NULL)
-        return;
-
-    error = pbuf_take(q.get(), &data.front(), data.size());
+    if (!q)
+        return;
+
+    error = pbuf_take(q.get(), &data.front(), (u16_t)data.size());
     if (error != ERR_OK)
         return;
Index: /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.rc
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.rc	(revision 75614)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.rc	(revision 75614)
@@ -0,0 +1,55 @@
+/* $Id$ */
+/** @file
+ * VBoxNetDHCP - Resource file containing version info.
+ */
+
+/*
+ * Copyright (C) 2015-2017 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+#include <windows.h>
+#include <VBox/version.h>
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+VS_VERSION_INFO VERSIONINFO
+  FILEVERSION      VBOX_RC_FILE_VERSION
+  PRODUCTVERSION   VBOX_RC_FILE_VERSION
+  FILEFLAGSMASK    VS_FFI_FILEFLAGSMASK
+  FILEFLAGS        VBOX_RC_FILE_FLAGS
+  FILEOS           VBOX_RC_FILE_OS
+  FILETYPE         VBOX_RC_TYPE_DLL
+  FILESUBTYPE      VFT2_UNKNOWN
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "040904b0" // Lang=US English, CharSet=Unicode
+    BEGIN
+      VALUE "CompanyName",      VBOX_RC_COMPANY_NAME
+      VALUE "FileDescription",  "VirtualBox DHCP Server\0"
+      VALUE "FileVersion",      VBOX_RC_FILE_VERSION_STR
+      VALUE "InternalName",     "VBoxNetDhcpd\0"
+      VALUE "LegalCopyright",   VBOX_RC_LEGAL_COPYRIGHT
+      VALUE "OriginalFilename", "VBoxNetDhcpd.dll\0"
+      VALUE "ProductName",      VBOX_RC_PRODUCT_NAME_STR
+      VALUE "ProductVersion",   VBOX_RC_PRODUCT_VERSION_STR
+      VBOX_RC_MORE_STRINGS
+    END
+  END
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x409, 1200
+  END
+END
+
+/* Creates the application icon. */
+#include "VBoxNetDhcpd-icon.rc"
+
Index: /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpdHardened.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpdHardened.cpp	(revision 75614)
+++ /trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpdHardened.cpp	(revision 75614)
@@ -0,0 +1,25 @@
+/* $Id$ */
+/** @file
+ * VBoxNetDhcpd - Hardened main().
+ */
+
+/*
+ * Copyright (C) 2009-2018 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+#include <VBox/sup.h>
+
+
+int main(int argc, char **argv, char **envp)
+{
+    return SUPR3HardenedMain("VBoxNetDhcpd", 0 /* fFlags */, argc, argv, envp);
+}
+
Index: /trunk/src/VBox/NetworkServices/Makefile.kmk
===================================================================
--- /trunk/src/VBox/NetworkServices/Makefile.kmk	(revision 75613)
+++ /trunk/src/VBox/NetworkServices/Makefile.kmk	(revision 75614)
@@ -22,5 +22,9 @@
 ifdef VBOX_WITH_MAIN
  # Include sub-makefiles.
- include $(PATH_SUB_CURRENT)/DHCP/Makefile.kmk
+ ifndef VBOX_WITH_DHCPD
+  include $(PATH_SUB_CURRENT)/DHCP/Makefile.kmk
+ else
+  include $(PATH_SUB_CURRENT)/Dhcpd/Makefile.kmk
+ endif
  ifdef VBOX_WITH_NAT_SERVICE
   include $(PATH_SUB_CURRENT)/NAT/Makefile.kmk
