Index: trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 41986)
+++ trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 41987)
@@ -354,4 +354,6 @@
     rc = slirpInitializeDnsSettings(pData);
     AssertRCReturn(rc, VINF_NAT_DNS);
+    rc = slirpTftpInit(pData);
+    AssertRCReturn(rc, VINF_NAT_DNS);
 
     if (i32AliasMode & ~(PKT_ALIAS_LOG|PKT_ALIAS_SAME_PORTS|PKT_ALIAS_PROXY_ONLY))
Index: trunk/src/VBox/Devices/Network/slirp/slirp_state.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/slirp_state.h	(revision 41986)
+++ trunk/src/VBox/Devices/Network/slirp/slirp_state.h	(revision 41987)
@@ -48,29 +48,4 @@
 
 /** TFTP session entry. */
-typedef enum ENMTFTPSESSIONFMT
-{
-    TFTPFMT_NONE = 0,
-    TFTPFMT_OCTET,
-    TFTPFMT_NETASCII,
-    TFTPFMT_MAIL,
-    TFTPFMT_NOT_FMT = 0xffff
-} ENMTFTPSESSIONFMT;
-
-typedef struct TFTPSESSION
-{
-    int         fInUse;
-    unsigned char pszFilename[TFTP_FILENAME_MAX];
-    struct      in_addr IpClientAddress;
-    uint16_t    u16ClientPort;
-    int         iTimestamp;
-    ENMTFTPSESSIONFMT enmTftpFmt;
-    uint16_t    u16BlkSize;
-    uint16_t    u16TSize;
-    uint16_t    u16Size;
-    uint16_t    u16Timeout;
-} TFTPSESSION, *PTFTPSESSION;
-
-typedef const PTFTPSESSION PCTFTPSESSION;
-
 struct dns_domain_entry
 {
@@ -196,5 +171,6 @@
     int tcp_reass_overflows;
     /* Stuff from tftp.c */
-    TFTPSESSION aTftpSessions[TFTP_SESSIONS_MAX];
+    void         *pvTftpSessions;
+    int          cTftpSession;
     const char *tftp_prefix;
     /* Stuff from udp.c */
Index: trunk/src/VBox/Devices/Network/slirp/tftp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/tftp.c	(revision 41986)
+++ trunk/src/VBox/Devices/Network/slirp/tftp.c	(revision 41987)
@@ -46,4 +46,49 @@
 #include <iprt/asm-math.h>
 
+typedef enum ENMTFTPSESSIONFMT
+{
+    TFTPFMT_NONE = 0,
+    TFTPFMT_OCTET,
+    TFTPFMT_NETASCII,
+    TFTPFMT_MAIL,
+    TFTPFMT_NOT_FMT = 0xffff
+} ENMTFTPSESSIONFMT;
+
+typedef struct TFTPSESSION
+{
+    int         fInUse;
+    unsigned char pszFilename[TFTP_FILENAME_MAX];
+    struct      in_addr IpClientAddress;
+    uint16_t    u16ClientPort;
+    int         iTimestamp;
+    ENMTFTPSESSIONFMT enmTftpFmt;
+    uint16_t    u16BlkSize;
+    uint16_t    u16TSize;
+    uint16_t    u16Size;
+    uint16_t    u16Timeout;
+} TFTPSESSION, *PTFTPSESSION, **PPTFTPSESSION;
+
+#pragma pack(1)
+typedef struct TFTPCOREHDR
+{
+    uint16_t    u16TftpOpCode;
+    /* Data lays here (might be raw uint8_t* or header of payload ) */
+} TFTPCOREHDR, *PTFTPCOREHDR;
+
+typedef struct TFTPIPHDR
+{
+    struct ip       IPv4Hdr;
+    struct udphdr   UdpHdr;
+    uint16_t        u16TftpOpType;
+    TFTPCOREHDR     Core;
+    /* Data lays here */
+} TFTPIPHDR, *PTFTPIPHDR;
+#pragma pack()
+
+typedef const PTFTPIPHDR PCTFTPIPHDR;
+
+typedef const PTFTPSESSION PCTFTPSESSION;
+
+
 typedef struct TFTPOPTIONDESC
 {
@@ -297,13 +342,16 @@
 }
 
-static int tftpAllocateSession(PNATState pData, PCTFTPIPHDR pcTftpIpHeader)
-{
-    PTFTPSESSION pTftpSession;
+static int tftpAllocateSession(PNATState pData, PCTFTPIPHDR pcTftpIpHeader, PPTFTPSESSION ppTftpSession)
+{
+    PTFTPSESSION pTftpSession = NULL;
     int rc = VINF_SUCCESS;
     int idxSession;
+    AssertPtrReturn(pData, VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pcTftpIpHeader, VERR_INVALID_PARAMETER);
+    AssertPtrReturn(ppTftpSession, VERR_INVALID_PARAMETER);
 
     for (idxSession = 0; idxSession < TFTP_SESSIONS_MAX; idxSession++)
     {
-        pTftpSession = &pData->aTftpSessions[idxSession];
+        pTftpSession = &((PTFTPSESSION)pData->pvTftpSessions)[idxSession];
 
         if (!pTftpSession->fInUse)
@@ -315,5 +363,5 @@
     }
 
-    return -1;
+    return VERR_NOT_FOUND;
 
  found:
@@ -322,19 +370,23 @@
     pTftpSession->u16ClientPort = pcTftpIpHeader->UdpHdr.uh_sport;
     rc = tftpSessionOptionParse(pTftpSession, pcTftpIpHeader);
-    AssertRCReturn(rc, -1);
+    AssertRCReturn(rc, VERR_INTERNAL_ERROR);
+    *ppTftpSession = pTftpSession;
 
     tftpSessionUpdate(pData, pTftpSession);
 
-    return idxSession;
-}
-
-static int tftpSessionFind(PNATState pData, PCTFTPIPHDR pcTftpIpHeader)
+    return VINF_SUCCESS;
+}
+
+static int tftpSessionFind(PNATState pData, PCTFTPIPHDR pcTftpIpHeader, PPTFTPSESSION ppTftpSessions)
 {
     PTFTPSESSION pTftpSession;
-    int k;
-
-    for (k = 0; k < TFTP_SESSIONS_MAX; k++)
-    {
-        pTftpSession = &pData->aTftpSessions[k];
+    int idxTftpSession;
+    AssertPtrReturn(pData, VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pcTftpIpHeader, VERR_INVALID_PARAMETER);
+    AssertPtrReturn(ppTftpSessions, VERR_INVALID_PARAMETER);
+
+    for (idxTftpSession = 0; idxTftpSession < TFTP_SESSIONS_MAX; idxTftpSession++)
+    {
+        pTftpSession = &((PTFTPSESSION)pData->pvTftpSessions)[idxTftpSession];
 
         if (pTftpSession->fInUse)
@@ -343,10 +395,13 @@
             {
                 if (pTftpSession->u16ClientPort == pcTftpIpHeader->UdpHdr.uh_sport)
-                    return k;
+                {
+                    *ppTftpSessions = pTftpSession;
+                    return VINF_SUCCESS;
+                }
             }
         }
     }
 
-    return -1;
+    return VERR_NOT_FOUND;
 }
 
@@ -647,9 +702,9 @@
 DECLINLINE(void) tftpProcessRRQ(PNATState pData, PCTFTPIPHDR pTftpIpHeader, int pktlen)
 {
-    PTFTPSESSION pTftpSession;
-    int idxTftpSession = 0;
+    PTFTPSESSION pTftpSession = NULL;
     uint8_t *pu8Payload = NULL;
     int     cbPayload = 0;
     int cbFileName = 0;
+    int rc = VINF_SUCCESS;
 
     AssertPtrReturnVoid(pTftpIpHeader);
@@ -658,6 +713,7 @@
     LogFlowFunc(("ENTER: pTftpIpHeader:%p, pktlen:%d\n", pTftpIpHeader, pktlen));
 
-    idxTftpSession = tftpAllocateSession(pData, pTftpIpHeader);
-    if (idxTftpSession < 0)
+    rc = tftpAllocateSession(pData, pTftpIpHeader, &pTftpSession);
+    if (   RT_FAILURE(rc)
+        || pTftpSession == NULL)
     {
         LogFlowFuncLeave();
@@ -665,5 +721,4 @@
     }
 
-    pTftpSession = &pData->aTftpSessions[idxTftpSession];
     pu8Payload = (uint8_t *)&pTftpIpHeader->Core;
     cbPayload = pktlen - sizeof(TFTPIPHDR);
@@ -702,18 +757,25 @@
 static void tftpProcessACK(PNATState pData, PTFTPIPHDR pTftpIpHeader)
 {
-    int s;
-
-    s = tftpSessionFind(pData, pTftpIpHeader);
-    if (s < 0)
+    int rc;
+    PTFTPSESSION pTftpSession = NULL;
+
+    rc = tftpSessionFind(pData, pTftpIpHeader, &pTftpSession);
+    if (RT_FAILURE(rc))
         return;
 
-    if (tftpSendData(pData, &pData->aTftpSessions[s],
-                       RT_N2H_U16(pTftpIpHeader->Core.u16TftpOpCode) + 1, pTftpIpHeader) < 0)
-    {
-        /* XXX */
-    }
-}
-
-DECLCALLBACK(void) tftp_input(PNATState pData, struct mbuf *pMbuf)
+    AssertReturnVoid(tftpSendData(pData,
+                                    pTftpSession,
+                                    RT_N2H_U16(pTftpIpHeader->Core.u16TftpOpCode) + 1, pTftpIpHeader));
+}
+
+DECLCALLBACK(int) slirpTftpInit(PNATState pData)
+{
+    AssertPtrReturn(pData, VERR_INVALID_PARAMETER);
+    pData->pvTftpSessions = RTMemAllocZ(sizeof(TFTPSESSION) * TFTP_SESSIONS_MAX);
+    AssertPtrReturn(pData->pvTftpSessions, VERR_NO_MEMORY);
+    return VINF_SUCCESS;
+}
+
+DECLCALLBACK(int) slirpTftpInput(PNATState pData, struct mbuf *pMbuf)
 {
     PTFTPIPHDR pTftpIpHeader = NULL;
@@ -731,7 +793,7 @@
             tftpProcessACK(pData, pTftpIpHeader);
             break;
-        default:
-            LogFlowFuncLeave();
-            return;
-    }
-}
+        default:;
+    }
+    LogFlowFuncLeaveRC(VINF_SUCCESS);
+    return VINF_SUCCESS;
+}
Index: trunk/src/VBox/Devices/Network/slirp/tftp.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/tftp.h	(revision 41986)
+++ trunk/src/VBox/Devices/Network/slirp/tftp.h	(revision 41987)
@@ -18,4 +18,7 @@
 /* tftp defines */
 
+#ifndef _SLIRP_TFTP_H_
+#define _SLIRP_TFTP_H_
+
 #define TFTP_SESSIONS_MAX 3
 
@@ -31,51 +34,6 @@
 #define TFTP_FILENAME_MAX 512
 
-#if 0
-struct tftp_t
-{
-    struct ip ip;
-    struct udphdr udp;
-    u_int16_t tp_op;
-    union
-    {
-        struct
-        {
-            u_int16_t tp_block_nr;
-            u_int8_t  tp_buf[512];
-        } tp_data;
-        struct
-        {
-            u_int16_t tp_error_code;
-            u_int8_t  tp_msg[512];
-        } tp_error;
-        u_int8_t tp_buf[512 + 2];
-    } x;
-};
-#else
-#pragma pack(0)
-typedef struct TFTPCOREHDR
-{
-    uint16_t    u16TftpOpCode;
-#if 0
-    union {
-        uint16_t u16BlockNum;
-        uint16_t u16TftpErrorCode;
-    } X;
+
+int slirpTftpInput(PNATState pData, struct mbuf *m);
+int slirpTftpInit(PNATState);
 #endif
-    /* Data lays here (might be raw uint8_t* or header of payload ) */
-} TFTPCOREHDR, *PTFTPCOREHDR;
-
-typedef struct TFTPIPHDR
-{
-    struct ip       IPv4Hdr;
-    struct udphdr   UdpHdr;
-    uint16_t        u16TftpOpType;
-    TFTPCOREHDR     Core;
-    /* Data lays here */
-} TFTPIPHDR, *PTFTPIPHDR;
-#pragma pack()
-
-typedef const PTFTPIPHDR PCTFTPIPHDR;
-#endif
-
-void tftp_input(PNATState pData, struct mbuf *m);
Index: trunk/src/VBox/Devices/Network/slirp/udp.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 41986)
+++ trunk/src/VBox/Devices/Network/slirp/udp.c	(revision 41987)
@@ -204,5 +204,6 @@
         && CTL_CHECK(ip->ip_dst.s_addr, CTL_TFTP))
     {
-        tftp_input(pData, m);
+        if (pData->pvTftpSessions)
+            slirpTftpInput(pData, m);
         goto done_free_mbuf;
     }
