Index: trunk/src/VBox/Devices/Network/DrvNAT.cpp
===================================================================
--- trunk/src/VBox/Devices/Network/DrvNAT.cpp	(revision 16614)
+++ trunk/src/VBox/Devices/Network/DrvNAT.cpp	(revision 16653)
@@ -43,4 +43,5 @@
 # ifndef RT_OS_WINDOWS
 #  include <unistd.h>
+#  include <fcntl.h>
 #  include <poll.h>
 # endif
@@ -350,5 +351,5 @@
     unsigned int cBreak = 0;
 # else
-    struct pollfd *polls;
+    struct pollfd *polls = NULL;
 # endif
 
@@ -374,9 +375,10 @@
 # ifndef RT_OS_WINDOWS
         nFDs = slirp_get_nsock(pThis->pNATState);
-        polls = (struct pollfd *)RTMemAllocZ((2 + nFDs) * sizeof(struct pollfd)); /* allocation for all sockets + ICMP and Management pipe*/
+        polls = NULL;
+        polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t)); /* allocation for all sockets + Management pipe*/
         if (polls == NULL)
         {
             LogRel(("Can't allocate memory for polling\n"));
-            AssertRelease(polls);
+            return VERR_NO_MEMORY;
         }
 
@@ -386,8 +388,11 @@
         polls[0].fd = pThis->PipeRead;
         polls[0].events = POLLRDNORM|POLLPRI|POLLRDBAND; /* POLLRDBAND usually doesn't used on Linux but seems used on Solaris */
-        int cChangedFDs = poll(polls, nFDs + 2, ms ? ms : -1);
+        polls[0].revents = 0;
+
+        int cChangedFDs = poll(polls, nFDs + 1, ms ? ms : -1);
+        AssertRelease(cChangedFDs >= 0);
         if (cChangedFDs >= 0)
         {
-            slirp_select_poll(pThis->pNATState, &polls[1], nFDs + 1);
+            slirp_select_poll(pThis->pNATState, &polls[1], nFDs);
             if (polls[0].revents & (POLLRDNORM|POLLPRI|POLLRDBAND))
             {
Index: trunk/src/VBox/Devices/Network/slirp/if.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/if.c	(revision 16614)
+++ trunk/src/VBox/Devices/Network/slirp/if.c	(revision 16653)
@@ -186,5 +186,5 @@
     {
         /* check if we can really output */
-        if (!slirp_can_output(pData->pvUser)) 
+        if (!slirp_can_output(pData->pvUser))
         {
             Log(("if_start: can't send\n"));
Index: trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/ip_icmp.c	(revision 16614)
+++ trunk/src/VBox/Devices/Network/slirp/ip_icmp.c	(revision 16653)
@@ -101,4 +101,5 @@
     }
     fd_nonblock(pData->icmp_socket.s);
+    NSOCK_INC();
 #else /* RT_OS_WINDOWS */
     pData->hmIcmpLibrary = LoadLibrary("Iphlpapi.dll");
Index: trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 16614)
+++ trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 16653)
@@ -33,10 +33,18 @@
 #  define DO_UNIX_CHECK_FD_SET(so, events, fdset )  0 /*specific for Unix API */
 # else /* !VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */
-#  define DO_ENGAGE_EVENT1(so, fdset, label)            \
-    do {                                                \
-        polls[poll_index].fd = (so)->s;                 \
-        (so)->so_poll_index = poll_index;               \
-        polls[poll_index].events = N_(fdset ## _poll);  \
-        poll_index++;                                   \
+#  define DO_ENGAGE_EVENT1(so, fdset, label)                    \
+    do {                                                        \
+        AssertRelease(poll_index < (nfds));                     \
+        if(    so->so_poll_index != -1                          \
+            && so->s == polls[so->so_poll_index].fd) {          \
+            polls[poll_index].events |= N_(fdset ## _poll);     \
+            break; /* out of this loop */                       \
+        }                                                       \
+        AssertRelease(poll_index >= 0 && poll_index < (nfds));  \
+        polls[poll_index].fd = (so)->s;                         \
+        (so)->so_poll_index = poll_index;                       \
+        polls[poll_index].events = N_(fdset ## _poll);          \
+        polls[poll_index].revents = 0;                          \
+        poll_index++;                                           \
     } while(0)
 
@@ -44,4 +52,10 @@
 #  define DO_ENGAGE_EVENT2(so, fdset1, fdset2, label)                           \
     do {                                                                        \
+        AssertRelease(poll_index < (nfds));                     \
+        if(    so->so_poll_index != -1                          \
+            && so->s == polls[so->so_poll_index].fd) {          \
+            polls[poll_index].events |= N_(fdset1 ## _poll) | N_(fdset1 ## _poll);  \
+            break; /* out of this loop */                       \
+        }                                                       \
         polls[poll_index].fd = (so)->s;                                         \
         (so)->so_poll_index = poll_index;                                       \
@@ -689,4 +703,7 @@
         QSOCKET_FOREACH(so, so_next, tcp)
         /* { */
+#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
+            so->so_poll_index = -1;
+#endif
             STAM_COUNTER_INC(&pData->StatTCP);
 
@@ -758,4 +775,7 @@
 
             STAM_COUNTER_INC(&pData->StatUDP);
+#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
+            so->so_poll_index = -1;
+#endif
 
             /*
@@ -801,4 +821,5 @@
     *pnfds = VBOX_EVENT_COUNT;
 # else /* RT_OS_WINDOWS */
+    AssertRelease(poll_index <= *pnfds);
     *pnfds = poll_index;
 # endif /* !RT_OS_WINDOWS */
@@ -924,4 +945,5 @@
 
             LOG_NAT_SOCK(so, TCP, &NetworkEvents, readfds, writefds, xfds);
+
 
             /*
@@ -1089,6 +1111,8 @@
                     so->so_state = SS_NOFDREF;
                     TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
+                    CONTINUE(tcp);
                 }
                 /* Here should be other error handlings */
+                AssertRelease(!"shouldn't be here!!!");
             }
 #endif
Index: trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 16614)
+++ trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 16653)
@@ -66,4 +66,7 @@
         so->so_state = SS_NOFDREF;
         so->s = -1;
+#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
+        so->so_poll_index = -1;
+#endif
     }
     return so;
@@ -89,7 +92,8 @@
 #ifndef VBOX_WITH_SLIRP_MT
     if(so->so_next && so->so_prev)
+    {
         remque(pData, so);  /* crashes if so is not in a queue */
         NSOCK_DEC();
-    so->so_state = SS_NOFDREF; /* for debugging purposes */
+    }
 
     RTMemFree(so);
