From 719d9c94425e657f34e8315189855807c2a20a27 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 24 Oct 2009 01:01:08 +0000 Subject: [PATCH] Add the user's specified host name to XML output, if available. It looks like this: --- docs/nmap.dtd | 2 +- output.cc | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/nmap.dtd b/docs/nmap.dtd index 91e851522..93e3a5367 100644 --- a/docs/nmap.dtd +++ b/docs/nmap.dtd @@ -55,7 +55,7 @@ - + diff --git a/output.cc b/output.cc index 9962a7ac5..6cc23615b 100644 --- a/output.cc +++ b/output.cc @@ -1378,23 +1378,26 @@ static void print_MAC_XML_Info(Target * currenths) { /* Helper function to write the status and address/hostname info of a host into the XML log */ -static void write_xml_initial_hostinfo(Target * currenths, +static void write_xml_initial_hostinfo(Target *currenths, const char *status) { log_write(LOG_XML, "\n", status, reason_str(currenths->reason.reason_id, SINGULAR)); log_write(LOG_XML, "
\n", - currenths->targetipstr(), - (o.af() == AF_INET) ? "ipv4" : "ipv6"); + currenths->targetipstr(), (o.af() == AF_INET) ? "ipv4" : "ipv6"); print_MAC_XML_Info(currenths); - if (*currenths->HostName()) { - log_write(LOG_XML, - "\n", - currenths->HostName()); - } else { - /* If machine is up, put blank hostname so front ends know that no name - resolution is forthcoming */ - if (strcmp(status, "up") == 0) - log_write(LOG_XML, "\n"); + /* 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) { + log_write(LOG_XML, "\n"); + if (currenths->TargetName() != NULL) { + log_write(LOG_XML, "\n", + currenths->TargetName()); + } + if (*currenths->HostName()) { + log_write(LOG_XML, "\n", + currenths->HostName()); + } + log_write(LOG_XML, "\n"); } log_flush_all(); }