1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-19 20:59:01 +00:00

Change PortList::getPortState to return the default port state if the

port is unknown, instead of -1. This makes it a better fit with the
other accessor functions. For those callers that need to know whether a
port is in the default state or not, add PortList::portIsDefault.

Having getPortState return -1 for ports in the default state would cause
the slightly wrong

Discovered unknown port 88/udp on 192.168.0.190 is actually open

to be printed instead of

Discovered open|filtered port 88/udp on 192.168.0.190 is actually open
This commit is contained in:
david
2010-01-26 20:46:26 +00:00
parent 1f6c6d1aac
commit 549dc85ad3
4 changed files with 13 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)); */