Index: trunk/src/VBox/Main/ConsoleImpl.cpp
===================================================================
--- trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 20726)
+++ trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 20727)
@@ -3244,15 +3244,6 @@
 
 #ifdef VBOX_DYNAMIC_NET_ATTACH
-            if (VBOX_SUCCESS (vrc) &&
-                !((eAttachmentType == meAttachmentType[ulInstance]) ||
-                  (eAttachmentType == NetworkAttachmentType_Null &&
-                   meAttachmentType[ulInstance] == NetworkAttachmentType_Null)))
-            {
-                rc = doNetworkAdapterChange(pszAdapterName,
-                                            ulInstance, 0,
-                                            eAttachmentType,
-                                            &meAttachmentType[ulInstance],
-                                            aNetworkAdapter);
-            }
+            if (VBOX_SUCCESS (vrc) && !(eAttachmentType == meAttachmentType[ulInstance]))
+                rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter);
 #endif /* VBOX_DYNAMIC_NET_ATTACH */
 
@@ -3284,19 +3275,15 @@
  * @param   uInstance           The PDM device instance.
  * @param   uLun                The PDM LUN number of the drive.
- * @param   eAttachmentType     The new attachment type.
- * @param   meAttachmentType    The current attachment type.
  * @param   aNetworkAdapter     The network adapter whose attachment needs to be changed
  *
  * @note Locks this object for writing.
  */
-HRESULT Console::doNetworkAdapterChange (const char *pszDevice, unsigned uInstance,
-                                         unsigned uLun, NetworkAttachmentType_T eAttachmentType,
-                                         NetworkAttachmentType_T *meAttachmentType,
+HRESULT Console::doNetworkAdapterChange (const char *pszDevice,
+                                         unsigned uInstance,
+                                         unsigned uLun,
                                          INetworkAdapter *aNetworkAdapter)
 {
-    LogFlowThisFunc (("pszDevice=%p:{%s} uInstance=%u uLun=%u eAttachmentType=%d "
-                      "meAttachmentType=%p:{%d} aNetworkAdapter=%p\n",
-                      pszDevice, pszDevice, uInstance, uLun, eAttachmentType,
-                      meAttachmentType, *meAttachmentType, aNetworkAdapter));
+    LogFlowThisFunc (("pszDevice=%p:{%s} uInstance=%u uLun=%u aNetworkAdapter=%p\n",
+                      pszDevice, pszDevice, uInstance, uLun, aNetworkAdapter));
 
     AutoCaller autoCaller (this);
@@ -3317,7 +3304,6 @@
     PVMREQ pReq;
     int vrc = VMR3ReqCall (mpVM, 0 /*idDstCpu*/, &pReq, 0 /* no wait! */,
-                           (PFNRT) Console::changeNetworkAttachment, 7,
-                           this, pszDevice, uInstance, uLun, eAttachmentType,
-                           meAttachmentType, aNetworkAdapter);
+                           (PFNRT) Console::changeNetworkAttachment, 5,
+                           this, pszDevice, uInstance, uLun, aNetworkAdapter);
 
     /* leave the lock before waiting for a result (EMT will call us back!) */
@@ -3353,6 +3339,4 @@
  * @param   uInstance           The PDM device instance.
  * @param   uLun                The PDM LUN number of the drive.
- * @param   eAttachmentType     The new attachment type.
- * @param   meAttachmentType    The current attachment type.
  * @param   aNetworkAdapter     The network adapter whose attachment needs to be changed
  *
@@ -3360,14 +3344,12 @@
  * @note Locks the Console object for writing.
  */
-DECLCALLBACK(int) Console::changeNetworkAttachment (Console *pThis, const char *pszDevice,
-                                                    unsigned uInstance, unsigned uLun,
-                                                    NetworkAttachmentType_T eAttachmentType,
-                                                    NetworkAttachmentType_T *meAttachmentType,
+DECLCALLBACK(int) Console::changeNetworkAttachment (Console *pThis,
+                                                    const char *pszDevice,
+                                                    unsigned uInstance,
+                                                    unsigned uLun,
                                                     INetworkAdapter *aNetworkAdapter)
 {
-    LogFlowFunc (("pThis=%p pszDevice=%p:{%s} uInstance=%u uLun=%u eAttachmentType=%d "
-                  "meAttachmentType=%p{%d} aNetworkAdapter=%p\n",
-                  pThis, pszDevice, pszDevice, uInstance, uLun, eAttachmentType,
-                  meAttachmentType, *meAttachmentType, aNetworkAdapter));
+    LogFlowFunc (("pThis=%p pszDevice=%p:{%s} uInstance=%u uLun=%u aNetworkAdapter=%p\n",
+                  pThis, pszDevice, pszDevice, uInstance, uLun, aNetworkAdapter));
 
     AssertReturn (pThis, VERR_INVALID_PARAMETER);
@@ -3433,6 +3415,5 @@
      * failing to attach.
      */
-    rcRet = configNetwork(pThis, pszDevice, uInstance, uLun, eAttachmentType, meAttachmentType,
-                          aNetworkAdapter, pCfg, pLunL0, pInst, true);
+    rcRet = configNetwork(pThis, pszDevice, uInstance, uLun, aNetworkAdapter, pCfg, pLunL0, pInst, true);
 
     /*
Index: trunk/src/VBox/Main/ConsoleImpl2.cpp
===================================================================
--- trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 20726)
+++ trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 20727)
@@ -1351,9 +1351,6 @@
          * Configure the network card now
          */
-        NetworkAttachmentType_T networkAttachment;
-        hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment);        H();
-
-        rc = configNetwork((Console*) pvConsole, pszAdapterName, ulInstance, 0, networkAttachment,
-                           &meAttachmentType[ulInstance], networkAdapter, pCfg, pLunL0, pInst, false);
+
+        rc = configNetwork(pConsole, pszAdapterName, ulInstance, 0, networkAdapter, pCfg, pLunL0, pInst, false);
         RC_CHECK();
     }
@@ -2054,6 +2051,4 @@
  *  @param   uInstance           The PDM device instance.
  *  @param   uLun                The PDM LUN number of the drive.
- *  @param   eAttachmentType     The new attachment type.
- *  @param   meAttachmentType    The current attachment type.
  *  @param   aNetworkAdapter     The network adapter whose attachment needs to be changed
  *
@@ -2062,6 +2057,4 @@
 DECLCALLBACK(int)  Console::configNetwork(Console *pThis, const char *pszDevice,
                                           unsigned uInstance, unsigned uLun,
-                                          NetworkAttachmentType_T eAttachmentType,
-                                          NetworkAttachmentType_T *meAttachmentType,
                                           INetworkAdapter *aNetworkAdapter,
                                           PCFGMNODE pCfg, PCFGMNODE pLunL0,
@@ -2145,4 +2138,7 @@
 
         Bstr networkName, trunkName, trunkType;
+        NetworkAttachmentType_T eAttachmentType;
+        hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType);
+        H();
         switch (eAttachmentType)
         {
@@ -2847,4 +2843,13 @@
                     }
 
+                    {
+                        /** @todo r=pritesh: get the dhcp server name from the
+                         * previous network configuration and then stop the server
+                         * else it may conflict with the dhcp server running  with
+                         * the current attachment type
+                         */
+                        /* Stop the hostonly DHCP Server */
+                    }
+
                     if(!networkName.isNull())
                     {
@@ -2884,5 +2889,5 @@
         }
 
-        *meAttachmentType = eAttachmentType;
+        meAttachmentType[uInstance] = eAttachmentType;
     }
     while (0);
Index: trunk/src/VBox/Main/include/ConsoleImpl.h
===================================================================
--- trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 20726)
+++ trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 20727)
@@ -432,6 +432,4 @@
     static DECLCALLBACK(int) configNetwork(Console *pThis, const char *pszDevice,
                                            unsigned uInstance, unsigned uLun,
-                                           NetworkAttachmentType_T eAttachmentType,
-                                           NetworkAttachmentType_T *meAttachmentType,
                                            INetworkAdapter *aNetworkAdapter,
                                            PCFGMNODE pCfg, PCFGMNODE pLunL0,
@@ -449,11 +447,7 @@
 #ifdef VBOX_DYNAMIC_NET_ATTACH
     HRESULT doNetworkAdapterChange (const char *pszDevice, unsigned uInstance,
-                                    unsigned uLun, NetworkAttachmentType_T eAttachmentType,
-                                    NetworkAttachmentType_T *meAttachmentType,
-                                    INetworkAdapter *aNetworkAdapter);
+                                    unsigned uLun, INetworkAdapter *aNetworkAdapter);
     static DECLCALLBACK(int) changeNetworkAttachment (Console *pThis, const char *pszDevice,
                                                       unsigned uInstance, unsigned uLun,
-                                                      NetworkAttachmentType_T eAttachmentType,
-                                                      NetworkAttachmentType_T *meAttachmentType,
                                                       INetworkAdapter *aNetworkAdapter);
 #endif /* VBOX_DYNAMIC_NET_ATTACH */
