diff --git a/service_scan.cc b/service_scan.cc index 604d06a08..2c4e00312 100644 --- a/service_scan.cc +++ b/service_scan.cc @@ -1175,7 +1175,7 @@ void AllProbes::service_scan_free(void) // If the buf (of length buflen) matches one of the regexes in this -// ServiceProbe, returns the details of the match (service name, +// ServiceProbe, returns the details of nth match (service name, // version number if applicable, and whether this is a "soft" match. // If the buf doesn't match, the serviceName field in the structure // will be NULL. The MatchDetails returned is only valid until the @@ -1183,14 +1183,17 @@ void AllProbes::service_scan_free(void) // serviceName field can be saved throughought program execution. If // no version matched, that field will be NULL. This function may // return NULL if there are no match lines at all in this probe. -const struct MatchDetails *ServiceProbe::testMatch(const u8 *buf, int buflen) { +const struct MatchDetails *ServiceProbe::testMatch(const u8 *buf, int buflen, int n = 0) { vector::iterator vi; const struct MatchDetails *MD; for(vi = matches.begin(); vi != matches.end(); vi++) { MD = (*vi)->testMatch(buf, buflen); - if (MD->serviceName) - return MD; + if (MD->serviceName) { + if (n == 0) + return MD; + n--; + } } return NULL; diff --git a/service_scan.h b/service_scan.h index da5a77f1d..c1e19af43 100644 --- a/service_scan.h +++ b/service_scan.h @@ -279,7 +279,7 @@ class ServiceProbe { void addMatch(const char *match, int lineno); // If the buf (of length buflen) matches one of the regexes in this - // ServiceProbe, returns the details of the match (service name, + // ServiceProbe, returns the details of the nth match (service name, // version number if applicable, and whether this is a "soft" match. // If the buf doesn't match, the serviceName field in the structure // will be NULL. The MatchDetails returned is only valid until the @@ -287,7 +287,7 @@ class ServiceProbe { // serviceName field can be saved throughought program execution. If // no version matched, that field will be NULL. This function may // return NULL if there are no match lines at all in this probe. - const struct MatchDetails *testMatch(const u8 *buf, int buflen); + const struct MatchDetails *testMatch(const u8 *buf, int buflen, int n); char *fallbackStr; ServiceProbe *fallbacks[MAXFALLBACKS+1];