Changeset 59313 in vbox
- Timestamp:
- Jan 12, 2016 3:00:48 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/hostres.c
r59220 r59313 142 142 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 143 143 static void alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *h); 144 static PDNSMAPPINGENTRY getDNSMapByName(PNATState pData, const char *name); 144 145 #endif 145 146 … … 458 459 struct dnsmsg_header *pHdr; 459 460 struct hostent *h; 461 struct hostent hostent; 462 char *h_aliases[1]; 463 char *h_addr_list[2]; 460 464 size_t oend; 461 465 size_t nanswers; … … 477 481 } 478 482 479 480 h = gethostbyname(name); 483 h = NULL; 484 #ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER 485 { 486 PDNSMAPPINGENTRY pDNSMapingEntry = getDNSMapByName(pData, name); 487 if (pDNSMapingEntry != NULL) 488 { 489 LogDbg(("NAT: hostres: %s resolved from %s%s\n", 490 name, 491 pDNSMapingEntry->fPattern ? "pattern " : "mapping", 492 pDNSMapingEntry->fPattern ? pDNSMapingEntry->pszName : "")); 493 494 if (qtype == Type_CNAME) 495 { 496 goto out; 497 } 498 499 hostent.h_name = name; 500 hostent.h_aliases = h_aliases; 501 h_aliases[0] = NULL; 502 hostent.h_addrtype = AF_INET; 503 hostent.h_length = sizeof(RTNETADDRIPV4); 504 hostent.h_addr_list = h_addr_list; 505 h_addr_list[0] = (char *)&pDNSMapingEntry->u32IpAddress; 506 h_addr_list[1] = NULL; 507 508 h = &hostent; 509 } 510 } 511 #endif 512 513 if (h == NULL) 514 { 515 h = gethostbyname(name); 516 } 517 481 518 if (h == NULL) 482 519 { … … 536 573 else if (qtype == Type_CNAME) 537 574 { 538 Log Err(("NAT: hostres: %s is already canonical\n", name));575 LogDbg(("NAT: hostres: %s is already canonical\n", name)); 539 576 goto out; /* NB: RCode_NoError without an answer, not RCode_NXDomain */ 540 577 } … … 1256 1293 1257 1294 1295 static PDNSMAPPINGENTRY 1296 getDNSMapByName(PNATState pData, const char *pszName) 1297 { 1298 PDNSMAPPINGENTRY pDNSMapingEntry; 1299 const char *pszNameLower; 1300 1301 pszNameLower = RTStrDup(pszName); 1302 if (RT_UNLIKELY(pszNameLower == NULL)) 1303 return NULL; 1304 RTStrToLower(pszNameLower); 1305 1306 STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapNames, MapList) 1307 { 1308 if (RTStrICmp(pDNSMapingEntry->pszName, pszNameLower) == 0) 1309 goto done; 1310 } 1311 1312 STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapPatterns, MapList) 1313 { 1314 if (RTStrSimplePatternMultiMatch(pDNSMapingEntry->pszName, RTSTR_MAX, 1315 pszNameLower, RTSTR_MAX, NULL)) 1316 goto done; 1317 } 1318 1319 done: 1320 RTStrFree(pszNameLower); 1321 return pDNSMapingEntry; 1322 } 1323 1324 1258 1325 static void 1259 1326 alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *h) 1260 1327 { 1261 1328 PDNSMAPPINGENTRY pDNSMapingEntry = NULL; 1262 char **pszAlias; 1263 1264 STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapNames, MapList) 1265 { 1266 Assert(!pDNSMapingEntry->fPattern); 1267 1268 if (RTStrICmp(pDNSMapingEntry->pszName, h->h_name) == 0) 1329 char **ppszAlias; 1330 1331 if (h->h_name != NULL) 1332 { 1333 pDNSMapingEntry = getDNSMapByName(pData, h->h_name); 1334 if (pDNSMapingEntry != NULL) 1269 1335 goto done; 1270 1271 for (pszAlias = h->h_aliases; *pszAlias != NULL; ++pszAlias) 1272 { 1273 if (RTStrICmp(pDNSMapingEntry->pszName, *pszAlias) == 0) 1274 goto done; 1275 } 1276 } 1277 1278 1279 # define MATCH(_pattern, _string) \ 1280 (RTStrSimplePatternMultiMatch((_pattern), RTSTR_MAX, (_string), RTSTR_MAX, NULL)) 1281 1282 STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapPatterns, MapList) 1283 { 1284 RTStrToLower(h->h_name); 1285 if (MATCH(pDNSMapingEntry->pszName, h->h_name)) 1336 } 1337 1338 for (ppszAlias = h->h_aliases; *ppszAlias != NULL; ++ppszAlias) 1339 { 1340 pDNSMapingEntry = getDNSMapByName(pData, *ppszAlias); 1341 if (pDNSMapingEntry != NULL) 1286 1342 goto done; 1287 1288 for (pszAlias = h->h_aliases; *pszAlias != NULL; ++pszAlias)1289 {1290 RTStrToLower(*pszAlias);1291 if (MATCH(pDNSMapingEntry->pszName, h->h_name))1292 goto done;1293 }1294 1343 } 1295 1344 … … 1301 1350 } 1302 1351 } 1303 #endif 1352 #endif /* VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER */
Note:
See TracChangeset
for help on using the changeset viewer.