diff --git a/CHANGELOG b/CHANGELOG index 10a04d643..a42302a31 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Nmap Changelog ($Id$); -*-text-*- +o Reduced the size of Port structures by about a third (from 176 to 64 + bytes on x86_64). They had accidentally been made bigger than they + should during the IPv6 code merge. [David Fifield] + o [NSE] Added default values for Expires, Call-ID, Allow and Content-Length headers in SIP requests and removed redundant code sip library. [Hani Benhabiles] diff --git a/output.cc b/output.cc index d045b74f6..55c2d830e 100644 --- a/output.cc +++ b/output.cc @@ -662,8 +662,11 @@ void printportoutput(Target *currenths, PortList *plist) { xml_attribute("state", "%s", state); xml_attribute("reason", "%s", reason_str(current->reason.reason_id, SINGULAR)); xml_attribute("reason_ttl", "%d", current->reason.ttl); - if (current->reason.ip_addr.ss_family != AF_UNSPEC) - xml_attribute("reason_ip", "%s", inet_ntop_ez(¤t->reason.ip_addr, sizeof(current->reason.ip_addr))); + if (current->reason.ip_addr.sockaddr.sa_family != AF_UNSPEC) { + struct sockaddr_storage ss; + memcpy(&ss, ¤t->reason.ip_addr, sizeof(current->reason.ip_addr)); + xml_attribute("reason_ip", "%s", inet_ntop_ez(&ss, sizeof(ss))); + } xml_close_empty_tag(); if (proto && proto->p_name && *proto->p_name) { @@ -774,8 +777,11 @@ void printportoutput(Target *currenths, PortList *plist) { xml_attribute("state", "%s", state); xml_attribute("reason", "%s", reason_str(current->reason.reason_id, SINGULAR)); xml_attribute("reason_ttl", "%d", current->reason.ttl); - if (current->reason.ip_addr.ss_family != AF_UNSPEC) - xml_attribute("reason_ip", "%s", inet_ntop_ez(¤t->reason.ip_addr, sizeof(current->reason.ip_addr))); + if (current->reason.ip_addr.sockaddr.sa_family != AF_UNSPEC) { + struct sockaddr_storage ss; + memcpy(&ss, ¤t->reason.ip_addr, sizeof(current->reason.ip_addr)); + xml_attribute("reason_ip", "%s", inet_ntop_ez(&ss, sizeof(ss))); + } xml_close_empty_tag(); if (sd.name || sd.service_fp || sd.service_tunnel != SERVICE_TUNNEL_NONE) diff --git a/portlist.cc b/portlist.cc index 6d71044d9..e5f342efa 100644 --- a/portlist.cc +++ b/portlist.cc @@ -928,9 +928,9 @@ int PortList::setStateReason(u16 portno, u8 proto, reason_t reason, u8 ttl, /* set new reason and increment its count */ answer->reason.reason_id = reason; if (ip_addr == NULL) - answer->reason.ip_addr.ss_family = AF_UNSPEC; + answer->reason.ip_addr.sockaddr.sa_family = AF_UNSPEC; else - answer->reason.ip_addr = *ip_addr; + answer->reason.set_ip_addr(ip_addr); answer->reason.ttl = ttl; return 0; } diff --git a/portreasons.cc b/portreasons.cc index 4f024b189..20488e31a 100644 --- a/portreasons.cc +++ b/portreasons.cc @@ -108,6 +108,21 @@ extern NmapOps o; class PortList; +/* Set the ip_addr union to the AF_INET or AF_INET6 value stored in *ss as + appropriate. Returns 0 on success or -1 if the address family of *ss is not + known. */ +int port_reason::set_ip_addr(const struct sockaddr_storage *ss) { + if (ss->ss_family == AF_INET) { + this->ip_addr.in = *(struct sockaddr_in *) ss; + return 0; + } else if (ss->ss_family == AF_INET6) { + this->ip_addr.in6 = *(struct sockaddr_in6 *) ss; + return 0; + } else { + return -1; + } +} + /* reason_string initializer */ reason_string::reason_string(){ this->plural = "unknown"; @@ -430,7 +445,7 @@ const char *reason_str(reason_t reason_code, unsigned int number) { void state_reason_init(state_reason_t *reason) { reason->reason_id = ER_UNKNOWN; - reason->ip_addr.ss_family = AF_UNSPEC; + reason->ip_addr.sockaddr.sa_family = AF_UNSPEC; reason->ttl = 0; } @@ -506,8 +521,13 @@ char *target_reason_str(Target *t) { char *port_reason_str(state_reason_t r) { static char reason[128]; memset(reason,'\0', 128); - Snprintf(reason, 128, "%s%s%s", reason_str(r.reason_id, SINGULAR), - (r.ip_addr.ss_family==AF_UNSPEC)?"":" from ", - (r.ip_addr.ss_family==AF_UNSPEC)?"":inet_ntop_ez(&r.ip_addr, sizeof(r.ip_addr))); + if (r.ip_addr.sockaddr.sa_family == AF_UNSPEC) { + Snprintf(reason, sizeof(reason), "%s", reason_str(r.reason_id, SINGULAR)); + } else { + struct sockaddr_storage ss; + memcpy(&ss, &r.ip_addr, sizeof(r.ip_addr)); + Snprintf(reason, sizeof(reason), "%s from %s", reason_str(r.reason_id, SINGULAR), + inet_ntop_ez(&ss, sizeof(ss))); + } return reason; } diff --git a/portreasons.h b/portreasons.h index 94169525d..55635a2fa 100644 --- a/portreasons.h +++ b/portreasons.h @@ -128,8 +128,14 @@ public: * why a port is in a specific state */ typedef struct port_reason { reason_t reason_id; - struct sockaddr_storage ip_addr; + union { + struct sockaddr_in in; + struct sockaddr_in6 in6; + struct sockaddr sockaddr; + } ip_addr; unsigned short ttl; + + int set_ip_addr(const struct sockaddr_storage *ss); } state_reason_t; /* used to calculate state reason summaries. diff --git a/scan_engine.cc b/scan_engine.cc index ca36fc68e..416f40550 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -5381,7 +5381,7 @@ static int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) { hss->target->reason.reason_id = current_reason; hss->target->reason.ttl = hdr.ttl; if (sockaddr_storage_cmp(&hdr.src, &target_dst) != 0) { - hss->target->reason.ip_addr = hdr.src; + hss->target->reason.set_ip_addr(&hdr.src); } } }