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

Add a PortList::hasOpenPorts member function to find out if a host has

any open, open|filtered, or unfiltered ports (those that would be
displayed by --open).
This commit is contained in:
david
2010-03-12 20:48:03 +00:00
parent bc132b963c
commit 5b00a325c0
2 changed files with 12 additions and 4 deletions

View File

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

View File

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