1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 13:11:28 +00:00

Simplify sscanf pattern for parsing /etc/hosts

This commit is contained in:
dmiller
2024-04-25 17:12:27 +00:00
parent 1c751cf6d3
commit 0b79498c04

View File

@@ -1005,9 +1005,8 @@ static void parse_etchosts(const char *fname) {
// Skip any leading whitespace // Skip any leading whitespace
while (*tp == ' ' || *tp == '\t') tp++; while (*tp == ' ' || *tp == '\t') tp++;
std::stringstream pattern; static const char *pattern = "%" STR(INET6_ADDRSTRLEN) "s %255s";
pattern << "%" << INET6_ADDRSTRLEN << "s %255s"; if (sscanf(tp, pattern, ipaddrstr, hname) == 2)
if (sscanf(tp, pattern.str().c_str(), ipaddrstr, hname) == 2)
if (sockaddr_storage_inet_pton(ipaddrstr, &ia)) if (sockaddr_storage_inet_pton(ipaddrstr, &ia))
{ {
const std::string hname_ = hname; const std::string hname_ = hname;