diff --git a/idle_scan.cc b/idle_scan.cc index 492186a9a..0f6eb60bd 100644 --- a/idle_scan.cc +++ b/idle_scan.cc @@ -1043,7 +1043,7 @@ void idle_scan(Target *target, u16 *portarray, int numports, /* Now we go through the ports which were scanned but not determined to be open, and add them in the "closed" state */ for(portidx = 0; portidx < numports; portidx++) { - if (target->ports.getPortState(portarray[portidx], IPPROTO_TCP) == -1) { + if (target->ports.portIsDefault(portarray[portidx], IPPROTO_TCP)) { target->ports.setPortState(portarray[portidx], IPPROTO_TCP, PORT_CLOSEDFILTERED); target->ports.setStateReason(portarray[portidx], IPPROTO_TCP, ER_NOIPIDCHANGE, 0, 0); } else diff --git a/portlist.cc b/portlist.cc index 2bd7edafe..c542c173f 100644 --- a/portlist.cc +++ b/portlist.cc @@ -535,19 +535,23 @@ void PortList::setPortState(u16 portno, u8 protocol, int state) { return; } -/* Return the current port state, if a Port has been allocated for this port. - Returns -1 if the port hasn't had anything about it set yet--in particular, - this function does not return the default port state by default. */ int PortList::getPortState(u16 portno, u8 protocol) { const Port *port; port = lookupPort(portno, protocol); if (port == NULL) - return -1; + return default_port_state[INPROTO2PORTLISTPROTO(protocol)].state; return port->state; } +/* Return true if nothing special is known about this port; i.e., it's in the + default state as defiend by setDefaultPortState and every other data field is + unset. */ +bool PortList::portIsDefault(u16 portno, u8 protocol) { + return lookupPort(portno, protocol) == NULL; +} + /* Saves an identification string for the target containing these ports (an IP address might be a good example, but set what you want). Only used when printing new port updates. Optional. A diff --git a/portlist.h b/portlist.h index 1fe1b20df..470c99974 100644 --- a/portlist.h +++ b/portlist.h @@ -221,6 +221,7 @@ class PortList { void setPortState(u16 portno, u8 protocol, int state); int getPortState(u16 portno, u8 protocol); int forgetPort(u16 portno, u8 protocol); + bool portIsDefault(u16 portno, u8 protocol); /* Saves an identification string for the target containing these ports (an IP addrss might be a good example, but set what you want). Only used when printing new port updates. Optional. A diff --git a/scan_engine.cc b/scan_engine.cc index 98817890f..234c92767 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -2630,10 +2630,11 @@ static bool ultrascan_port_pspec_update(UltraScanInfo *USI, portno = pspec->pd.sctp.dport; } else assert(0); - oldstate = hss->target->ports.getPortState(portno, proto); - if (oldstate == -1) { + if (hss->target->ports.portIsDefault(portno, proto)) { oldstate = PORT_TESTING; hss->ports_finished++; + } else { + oldstate = hss->target->ports.getPortState(portno, proto); } /* printf("TCP port %hu has changed from state %s to %s!\n", portno, statenum2str(oldstate), statenum2str(newstate)); */