mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Read multiple hostnames for one address from /etc/hosts
This commit is contained in:
23
nmap_dns.cc
23
nmap_dns.cc
@@ -1094,19 +1094,22 @@ static void parse_etchosts(const char *fname) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ialen = hname.find('#');
|
|
||||||
|
|
||||||
// If hostname is a comment or address begins a comment, no good.
|
// If hostname is a comment or address begins a comment, no good.
|
||||||
if (ialen == 0 || addr.find('#') != std::string::npos) {
|
if (hname[0] == '#' || addr.find('#') != std::string::npos) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's a comment in the hostname, strip it.
|
|
||||||
if (ialen != std::string::npos) {
|
|
||||||
hname.erase(ialen);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == resolve_numeric(addr.c_str(), 0, &ia, &ialen, AF_UNSPEC)) {
|
if (0 == resolve_numeric(addr.c_str(), 0, &ia, &ialen, AF_UNSPEC)) {
|
||||||
|
size_t commentpos = std::string::npos;
|
||||||
|
bool first = true;
|
||||||
|
do {
|
||||||
|
// If there's a comment in the hostname, strip it.
|
||||||
|
commentpos = hname.find('#');
|
||||||
|
if (commentpos != std::string::npos) {
|
||||||
|
hname.erase(commentpos);
|
||||||
|
}
|
||||||
|
if (!hname.empty()) {
|
||||||
|
if (first)
|
||||||
host_cache.add(ia, hname);
|
host_cache.add(ia, hname);
|
||||||
if (ia.ss_family == AF_INET) {
|
if (ia.ss_family == AF_INET) {
|
||||||
etchosts[NameRecord(hname, DNS::A)] = ia;
|
etchosts[NameRecord(hname, DNS::A)] = ia;
|
||||||
@@ -1115,6 +1118,10 @@ static void parse_etchosts(const char *fname) {
|
|||||||
etchosts[NameRecord(hname, DNS::AAAA)] = ia;
|
etchosts[NameRecord(hname, DNS::AAAA)] = ia;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
first = false;
|
||||||
|
// Keep going until we find a comment or run out of tokens
|
||||||
|
} while (commentpos == std::string::npos && (iss >> hname));
|
||||||
|
}
|
||||||
else if (o.debugging)
|
else if (o.debugging)
|
||||||
log_write(LOG_STDOUT, "Unable to parse /etc/hosts address: %s\n", addr.c_str());
|
log_write(LOG_STDOUT, "Unable to parse /etc/hosts address: %s\n", addr.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user