diff --git a/output.cc b/output.cc index 003306297..36be0a23d 100644 --- a/output.cc +++ b/output.cc @@ -1271,7 +1271,7 @@ static void write_xml_initial_hostinfo(const Target *currenths, print_MAC_XML_Info(currenths); /* Output a hostnames element whenever we have a name to write or the target is up. */ - if (currenths->TargetName() != NULL || *currenths->HostName() || strcmp(status, "up") == 0) { + if (currenths->TargetName() != NULL || *currenths->HostName() || strcmp(status, "up") == 0 || !currenths->getTargetNameAliases().empty()) { xml_start_tag("hostnames"); xml_newline(); if (currenths->TargetName() != NULL) { @@ -1282,9 +1282,10 @@ static void write_xml_initial_hostinfo(const Target *currenths, xml_newline(); } /* Print additional names collected when --unique suppressed duplicate scanning. */ - for (const std::string &alias : currenths->getTargetNameAliases()) { + for (std::vector::const_iterator alias = currenths->getTargetNameAliases().begin(); + alias != currenths->getTargetNameAliases().end(); ++alias) { xml_open_start_tag("hostname"); - xml_attribute("name", "%s", alias.c_str()); + xml_attribute("name", "%s", alias->c_str()); xml_attribute("type", "user"); xml_close_empty_tag(); xml_newline(); diff --git a/targets.cc b/targets.cc index 2682f6f6b..7255bbc01 100644 --- a/targets.cc +++ b/targets.cc @@ -481,6 +481,7 @@ bool HostGroupState::get_next_host(struct sockaddr_storage *ss, size_t *sslen, s Note: Nmap's streaming XML architecture finalizes and closes blocks after each batch. Therefore, it is impossible to attach aliases to duplicates that occur in a later batch than the original target without buffering + all XML in memory. We restrict our search to the current batch. */ if (o.unique && current_group.get_namedhost() && current_group.is_resolved_address(ss)) { const char *skipped_name = current_group.get_resolved_name();