diff --git a/portlist.cc b/portlist.cc index 5cd7fa56e..4907bc6bd 100644 --- a/portlist.cc +++ b/portlist.cc @@ -567,11 +567,11 @@ void PortList::setIdStr(const char *id) { } -int PortList::getStateCounts(int protocol, int state){ +int PortList::getStateCounts(int protocol, int state) const { return state_counts_proto[INPROTO2PORTLISTPROTO(protocol)][state]; } -int PortList::getStateCounts(int state){ +int PortList::getStateCounts(int state) const { int sum=0, proto; for(proto=0; proto < PORTLIST_PROTO_MAX; proto++) sum += getStateCounts(PORTLISTPROTO2INPROTO(proto), state); @@ -873,6 +873,13 @@ int PortList::numPorts() const { return num; } +/* Return true if any of the ports are potentially open. */ +bool PortList::hasOpenPorts() const { + return getStateCounts(PORT_OPEN) != 0 || + getStateCounts(PORT_OPENFILTERED) != 0 || + getStateCounts(PORT_UNFILTERED) != 0; +} + int PortList::setStateReason(u16 portno, u8 proto, reason_t reason, u8 ttl, u32 ip_addr) { Port *answer = NULL; diff --git a/portlist.h b/portlist.h index 470c99974..392d4426a 100644 --- a/portlist.h +++ b/portlist.h @@ -245,9 +245,9 @@ class PortList { int numscriptresults; /* Total number of scripts which produced output */ /* Get number of ports in this state. This a sum for protocols. */ - int getStateCounts(int state); + int getStateCounts(int state) const; /* Get number of ports in this state for requested protocol. */ - int getStateCounts(int protocol, int state); + int getStateCounts(int protocol, int state) const; // sname should be NULL if sres is not // PROBESTATE_FINISHED_MATCHED. product,version, and/or extrainfo @@ -299,6 +299,7 @@ class PortList { int numIgnoredStates(); int numIgnoredPorts(); int numPorts() const; + bool hasOpenPorts() const; private: bool mapPort(u16 *portno, u8 *protocol) const;