Index: trunk/src/VBox/Devices/Network/slirp/hostres.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/hostres.c	(revision 59312)
+++ trunk/src/VBox/Devices/Network/slirp/hostres.c	(revision 59313)
@@ -142,4 +142,5 @@
 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
 static void alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *h);
+static PDNSMAPPINGENTRY getDNSMapByName(PNATState pData, const char *name);
 #endif
 
@@ -458,4 +459,7 @@
     struct dnsmsg_header *pHdr;
     struct hostent *h;
+    struct hostent hostent;
+    char *h_aliases[1];
+    char *h_addr_list[2];
     size_t oend;
     size_t nanswers;
@@ -477,6 +481,39 @@
     }
 
-
-    h = gethostbyname(name);
+    h = NULL;
+#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
+    {
+        PDNSMAPPINGENTRY pDNSMapingEntry = getDNSMapByName(pData, name);
+        if (pDNSMapingEntry != NULL)
+        {
+            LogDbg(("NAT: hostres: %s resolved from %s%s\n",
+                    name,
+                    pDNSMapingEntry->fPattern ? "pattern " : "mapping",
+                    pDNSMapingEntry->fPattern ? pDNSMapingEntry->pszName : ""));
+
+            if (qtype == Type_CNAME)
+            {
+                goto out;
+            }
+
+            hostent.h_name = name;
+            hostent.h_aliases = h_aliases;
+            h_aliases[0] = NULL;
+            hostent.h_addrtype = AF_INET;
+            hostent.h_length = sizeof(RTNETADDRIPV4);
+            hostent.h_addr_list = h_addr_list;
+            h_addr_list[0] = (char *)&pDNSMapingEntry->u32IpAddress;
+            h_addr_list[1] = NULL;
+
+            h = &hostent;
+        }
+    }
+#endif
+
+    if (h == NULL)
+    {
+        h = gethostbyname(name);
+    }
+
     if (h == NULL)
     {
@@ -536,5 +573,5 @@
     else if (qtype == Type_CNAME)
     {
-        LogErr(("NAT: hostres: %s is already canonical\n", name));
+        LogDbg(("NAT: hostres: %s is already canonical\n", name));
         goto out; /* NB: RCode_NoError without an answer, not RCode_NXDomain */
     }
@@ -1256,40 +1293,52 @@
 
 
+static PDNSMAPPINGENTRY
+getDNSMapByName(PNATState pData, const char *pszName)
+{
+    PDNSMAPPINGENTRY pDNSMapingEntry;
+    const char *pszNameLower;
+
+    pszNameLower = RTStrDup(pszName);
+    if (RT_UNLIKELY(pszNameLower == NULL))
+        return NULL;
+    RTStrToLower(pszNameLower);
+
+    STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapNames, MapList)
+    {
+        if (RTStrICmp(pDNSMapingEntry->pszName, pszNameLower) == 0)
+            goto done;
+    }
+
+    STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapPatterns, MapList)
+    {
+        if (RTStrSimplePatternMultiMatch(pDNSMapingEntry->pszName, RTSTR_MAX,
+                                         pszNameLower, RTSTR_MAX, NULL))
+            goto done;
+    }
+
+  done:
+    RTStrFree(pszNameLower);
+    return pDNSMapingEntry;
+}
+
+
 static void
 alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *h)
 {
     PDNSMAPPINGENTRY pDNSMapingEntry = NULL;
-    char **pszAlias;
-
-    STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapNames, MapList)
-    {
-        Assert(!pDNSMapingEntry->fPattern);
-
-        if (RTStrICmp(pDNSMapingEntry->pszName, h->h_name) == 0)
+    char **ppszAlias;
+
+    if (h->h_name != NULL)
+    {
+        pDNSMapingEntry = getDNSMapByName(pData, h->h_name);
+        if (pDNSMapingEntry != NULL)
             goto done;
-
-        for (pszAlias = h->h_aliases; *pszAlias != NULL; ++pszAlias)
-        {
-            if (RTStrICmp(pDNSMapingEntry->pszName, *pszAlias) == 0)
-                goto done;
-        }
-    }
-
-
-#   define MATCH(_pattern, _string) \
-        (RTStrSimplePatternMultiMatch((_pattern), RTSTR_MAX, (_string), RTSTR_MAX, NULL))
-
-    STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapPatterns, MapList)
-    {
-        RTStrToLower(h->h_name);
-        if (MATCH(pDNSMapingEntry->pszName, h->h_name))
+    }
+
+    for (ppszAlias = h->h_aliases; *ppszAlias != NULL; ++ppszAlias)
+    {
+        pDNSMapingEntry = getDNSMapByName(pData, *ppszAlias);
+        if (pDNSMapingEntry != NULL)
             goto done;
-
-        for (pszAlias = h->h_aliases; *pszAlias != NULL; ++pszAlias)
-        {
-            RTStrToLower(*pszAlias);
-            if (MATCH(pDNSMapingEntry->pszName, h->h_name))
-                goto done;
-        }
     }
 
@@ -1301,3 +1350,3 @@
     }
 }
-#endif
+#endif /* VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER */
