1
0
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:
dmiller
2025-05-09 22:47:07 +00:00
parent 297a6242c7
commit 8fc566bf49

View File

@@ -1094,19 +1094,22 @@ static void parse_etchosts(const char *fname) {
continue;
}
ialen = hname.find('#');
// 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;
}
// 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)) {
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);
if (ia.ss_family == AF_INET) {
etchosts[NameRecord(hname, DNS::A)] = ia;
@@ -1115,6 +1118,10 @@ static void parse_etchosts(const char *fname) {
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)
log_write(LOG_STDOUT, "Unable to parse /etc/hosts address: %s\n", addr.c_str());
}