Index: trunk/src/VBox/Devices/Network/slirp/ip_output.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/ip_output.c	(revision 22940)
+++ trunk/src/VBox/Devices/Network/slirp/ip_output.c	(revision 22941)
@@ -131,28 +131,29 @@
     }
 #endif
-      /* Current TCP/IP stack hasn't routing information at
-       * all so we need to calculate destination ethernet address
-       */
-#ifndef VBOX_WITH_SLIRP_BSD_MBUF
-     eh = (struct ethhdr *)MBUF_HEAD(m);
-#else
-    /*todo: make prepend */
-    m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT);
-    Assert(m);
-    eh = mtod(m, struct ethhdr *);
-    m_adj(m, ETH_HLEN); /*let the rest of code do it job*/
-#endif
-     if (memcmp(eh->h_source, zerro_ethaddr, ETH_ALEN) == 0)
-     {
-        rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst);
-        if (rc != 0)
-            goto bad;
-     }
-     else
-    {
-        memcpy(eth_dst, eh->h_source, ETH_ALEN);
-        rc = 0; /*some times we've already know where to send packet*/
-    }
-
+    /* Current TCP/IP stack hasn't routing information at
+     * all so we need to calculate destination ethernet address
+     */
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
+    eh = (struct ethhdr *)MBUF_HEAD(m);
+    if (memcmp(eh->h_source, zerro_ethaddr, ETH_ALEN) == 0)
+    {
+       rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst);
+       if (rc != 0)
+           goto bad;
+    }
+    else
+    {
+       memcpy(eth_dst, eh->h_source, ETH_ALEN);
+       rc = 0; /*some times we've already know where to send packet*/
+    }
+#else
+    /* 
+     * (vvl) Note: Here we should care about dhcp and other services
+     * aware of ethernet address 
+     */
+    rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst);
+    if (rc != 0)
+        goto bad;
+#endif
     /*
      * If small enough for interface, can just send directly.
@@ -165,7 +166,4 @@
         ip->ip_sum = cksum(m, hlen);
     
-        Assert((rc == 0));
-        memcpy(eh->h_source, eth_dst, ETH_ALEN); 
-    
         {
             STAM_PROFILE_START(&pData->StatALIAS_output, a);
@@ -193,8 +191,15 @@
             STAM_PROFILE_STOP(&pData->StatALIAS_output, a);
         }
+#ifdef VBOX_WITH_SLIRP_BSD_MBUF
+        /*todo: make prepend */
+        m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT);
+        Assert(m);
+        eh = mtod(m, struct ethhdr *);
+#endif
+        memcpy(eh->h_source, eth_dst, ETH_ALEN); 
 
         if_output(pData, so, m);
         goto done;
-    }
+     }
 
     /*
@@ -254,16 +259,4 @@
 #endif
             /* we've calculated eth_dst for first packet */
-#ifndef VBOX_WITH_SLIRP_BSD_MBUF
-            eh = (struct ethhdr *)MBUF_HEAD(m);
-#else
-            m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT);
-            Assert(m);
-            eh = mtod(m, struct ethhdr *);
-            m_adj(m, ETH_HLEN);
-#endif
-            Assert((rc == 0));
-
-            memcpy(eh->h_source, eth_dst, ETH_ALEN); 
-
 #if 0 /* No options */
             if (hlen > sizeof (struct ip))
@@ -314,30 +307,4 @@
         ip->ip_sum = cksum(m, hlen);
 
-        {
-            STAM_PROFILE_START(&pData->StatALIAS_output, a);
-#ifndef VBOX_WITH_SLIRP_BSD_MBUF
-            rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias), 
-                mtod(m, char *), m->m_len);
-#else
-            struct m_tag *t;
-            if (t = m_tag_find(m, PACKET_TAG_ALIAS, NULL) != 0)
-            {
-                rc = LibAliasOut((struct libalias *)&t[1], mtod(m, char *), m_length(m, NULL));
-            }
-            else
-            {
-                rc = LibAliasOut(pData->proxy_alias, mtod(m, char *), 
-                                 m_length(m, NULL));
-            } 
-            if (rc == PKT_ALIAS_IGNORED)
-            {
-                Log(("NAT: packet was droppped\n"));
-                goto bad;
-            }
-#endif
-            Log2(("NAT: LibAlias return %d\n", rc));
-            STAM_PROFILE_STOP(&pData->StatALIAS_output, a);
-        }
-
 sendorfree:
         for (m = m0; m; m = m0)
@@ -369,4 +336,13 @@
 #endif
                 Log2(("NAT: LibAlias return %d\n", rc));
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
+                eh = (struct ethhdr *)MBUF_HEAD(m);
+#else
+                m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT);
+                Assert(m);
+                eh = mtod(m, struct ethhdr *);
+#endif
+                memcpy(eh->h_source, eth_dst, ETH_ALEN); 
+
                 if_output(pData, so, m);
             }
Index: trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 22940)
+++ trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 22941)
@@ -274,6 +274,8 @@
                 return VERR_NO_MEMORY;
             }
-            LogRel(("NAT: adding %R[IP4] to DNS server list\n", &((struct sockaddr_in *)saddr)->sin_addr));
-            if ((((struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) {
+            LogRel(("NAT: adding %R[IP4] to DNS server list\n", 
+                    &((struct sockaddr_in *)saddr)->sin_addr));
+            if ((((  struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == 
+                     ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) {
                 da->de_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
             }
@@ -554,5 +556,9 @@
 
     /* Initialise mbufs *after* setting the MTU */
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
     m_init(pData);
+#else
+    mbuf_init(pData);
+#endif
 
 #ifndef VBOX_WITH_NAT_SERVICE
@@ -1361,4 +1367,5 @@
     {
         case ARPOP_REQUEST:
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
             mr = m_get(pData);
 
@@ -1372,4 +1379,13 @@
             mr->m_len = sizeof(struct arphdr);
             rah = mtod(mr, struct arphdr *);
+#else
+            mr = m_gethdr(pData, M_NOWAIT, MT_HEADER);
+            rah = mtod(mr, struct arphdr *);
+            Assert(mr);
+            mr->m_pkthdr.len = mr->m_len = sizeof(* rah);
+            mr = m_prepend(pData, mr, ETH_HLEN, M_DONTWAIT);
+            reh = mtod(mr, struct ethhdr *);
+            memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/
+#endif
 #ifdef VBOX_WITH_NAT_SERVICE
             if (tip == special_addr.s_addr) goto arp_ok;
@@ -1473,8 +1489,13 @@
     }
 
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
     m = m_get(pData);
+#else
+    m = m_gethdr(pData, M_NOWAIT, MT_HEADER);
+#endif
     if (!m)
     {
         LogRel(("NAT: can't allocate new mbuf\n"));
+        RTMemFree((void *)pkt);
         return;
     }
@@ -1482,4 +1503,5 @@
     /* Note: we add to align the IP header */
 
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
     if (M_FREEROOM(m) < pkt_len)
        m_inc(m, pkt_len);
@@ -1487,4 +1509,12 @@
     m->m_len = pkt_len ;
     memcpy(m->m_data, pkt, pkt_len);
+#else
+    if (m_append(pData, m, pkt_len, pkt) != 1)
+    {
+        AssertMsgFailed(("Can't append incommin to mbuf"));
+        RTMemFree(pkt);
+        m_free(pData, m);
+    }
+#endif
 
 #if 1
@@ -1504,4 +1534,8 @@
             updtime(pData);
             m_adj(m, ETH_HLEN);
+#ifdef VBOX_WITH_SLIRP_BSD_MBUF
+            M_ASSERTPKTHDR(m);
+            m->m_pkthdr.header = mtod(m, void *);
+#endif
             ip_input(pData, m);
             break;
@@ -1527,6 +1561,8 @@
     struct ethhdr *eh;
     uint8_t *buf = NULL;
+    size_t mlen = 0;
     STAM_PROFILE_START(&pData->StatIF_encap, a);
 
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
     m->m_data -= if_maxlinkhdr;
     m->m_len += ETH_HLEN;
@@ -1538,4 +1574,8 @@
         AssertMsgFailed(("!!Ethernet frame corrupted!!"));
     }
+#else
+    M_ASSERTPKTHDR(m);
+    eh = mtod(m, struct ethhdr *);
+#endif
 
     if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) != 0)
@@ -1550,5 +1590,10 @@
         }
     }
-    buf = RTMemAlloc(1600);
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
+    mlen = m->m_len;
+#else
+    mlen = m_length(pData, m);
+#endif
+    buf = RTMemAlloc(mlen);
     if (buf == NULL)
     {
@@ -1557,6 +1602,10 @@
     }
     eh->h_proto = htons(eth_proto);
-    memcpy(buf, mtod(m, uint8_t *), m->m_len);
-    slirp_output(pData->pvUser, NULL, buf, m->m_len);
+#ifndef VBOX_WITH_SLIRP_BSD_MBUF
+    memcpy(buf, mtod(m, uint8_t *), mlen);
+#else
+    m_copydata(m, 0, mlen, (char *)buf);
+#endif
+    slirp_output(pData->pvUser, NULL, buf, mlen);
 done:
     STAM_PROFILE_STOP(&pData->StatIF_encap, a);
