1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41:29 +00:00

Remove the struct scan_lists parameter from getpts_aux and some of its auxiliary functions. It was used only to keep track of the number of ports and protocols, which can be derived after the bit map is filled in. This is preparation for a minor refactoring of getpts so it can be used for ping port selection.

This commit is contained in:
david
2007-10-30 04:40:10 +00:00
parent 83224a187c
commit 2dcf70d520
5 changed files with 21 additions and 22 deletions

32
nmap.cc
View File

@@ -2059,7 +2059,7 @@ void init_socket(int sd) {
* the outer part of the port expression. It's "closed". * the outer part of the port expression. It's "closed".
*/ */
static void getpts_aux(char *origexpr, int nested, u8 *porttbl, struct scan_lists *ports, int range_type, int static void getpts_aux(char *origexpr, int nested, u8 *porttbl, int range_type, int
*portwarning); *portwarning);
struct scan_lists *getpts(char *origexpr) { struct scan_lists *getpts(char *origexpr) {
@@ -2082,10 +2082,21 @@ struct scan_lists *getpts(char *origexpr) {
getpts_aux(origexpr, // Pass on the expression getpts_aux(origexpr, // Pass on the expression
0, // Don't start off nested 0, // Don't start off nested
porttbl, // Our allocated port table porttbl, // Our allocated port table
ports, // The destination structure - passed so we can track the number of tcp/udp/prot ports
range_type, // Defaults to TCP/UDP/Protos range_type, // Defaults to TCP/UDP/Protos
&portwarning); // No, we haven't warned them about dup ports yet &portwarning); // No, we haven't warned them about dup ports yet
ports->tcp_count = 0;
ports->udp_count = 0;
ports->prot_count = 0;
for(i = 0; i <= 65535; i++) {
if (porttbl[i] & SCAN_TCP_PORT)
ports->tcp_count++;
if (porttbl[i] & SCAN_UDP_PORT)
ports->udp_count++;
if (porttbl[i] & SCAN_PROTOCOLS && i < 256)
ports->prot_count++;
}
if (range_type != 0 && 0 == (ports->tcp_count + ports->udp_count + ports->prot_count)) if (range_type != 0 && 0 == (ports->tcp_count + ports->udp_count + ports->prot_count))
fatal("No ports specified -- If you really don't want to scan any ports use ping scan..."); fatal("No ports specified -- If you really don't want to scan any ports use ping scan...");
@@ -2117,7 +2128,7 @@ struct scan_lists *getpts(char *origexpr) {
/* getpts() (see above) is a wrapper for this function */ /* getpts() (see above) is a wrapper for this function */
static void getpts_aux(char *origexpr, int nested, u8 *porttbl, struct scan_lists *ports, int range_type, int *portwarning) { static void getpts_aux(char *origexpr, int nested, u8 *porttbl, int range_type, int *portwarning) {
long rangestart = -2343242, rangeend = -9324423; long rangestart = -2343242, rangeend = -9324423;
char *current_range; char *current_range;
char *endptr; char *endptr;
@@ -2148,7 +2159,7 @@ static void getpts_aux(char *origexpr, int nested, u8 *porttbl, struct scan_list
if (nested) if (nested)
fatal("Can't nest [] brackets in -p switch"); fatal("Can't nest [] brackets in -p switch");
getpts_aux(++current_range, 1, porttbl, ports, range_type, portwarning); getpts_aux(++current_range, 1, porttbl, range_type, portwarning);
// Skip past the ']'. This is OK because we can't nest []s // Skip past the ']'. This is OK because we can't nest []s
while(*current_range != ']') current_range++; while(*current_range != ']') current_range++;
@@ -2189,8 +2200,8 @@ static void getpts_aux(char *origexpr, int nested, u8 *porttbl, struct scan_list
if (*current_range && *current_range != ']') current_range++; // We want the '] character to be picked up on the next pass if (*current_range && *current_range != ']') current_range++; // We want the '] character to be picked up on the next pass
servmask[i] = '\0'; // Finish the string servmask[i] = '\0'; // Finish the string
i = addportsfromservmask(servmask, porttbl, ports, range_type); i = addportsfromservmask(servmask, porttbl, range_type);
if (range_type & SCAN_PROTOCOLS) i += addprotocolsfromservmask(servmask, porttbl, ports); if (range_type & SCAN_PROTOCOLS) i += addprotocolsfromservmask(servmask, porttbl);
if (i == 0) if (i == 0)
fatal("Found no matches for the service mask '%s' and your specified protocols", servmask); fatal("Found no matches for the service mask '%s' and your specified protocols", servmask);
@@ -2237,26 +2248,17 @@ static void getpts_aux(char *origexpr, int nested, u8 *porttbl, struct scan_list
if (nested) { if (nested) {
if ((range_type & SCAN_TCP_PORT) && if ((range_type & SCAN_TCP_PORT) &&
nmap_getservbyport(htons(rangestart), "tcp")) { nmap_getservbyport(htons(rangestart), "tcp")) {
ports->tcp_count++;
porttbl[rangestart] |= SCAN_TCP_PORT; porttbl[rangestart] |= SCAN_TCP_PORT;
} }
if ((range_type & SCAN_UDP_PORT) && if ((range_type & SCAN_UDP_PORT) &&
nmap_getservbyport(htons(rangestart), "udp")) { nmap_getservbyport(htons(rangestart), "udp")) {
ports->udp_count++;
porttbl[rangestart] |= SCAN_UDP_PORT; porttbl[rangestart] |= SCAN_UDP_PORT;
} }
if ((range_type & SCAN_PROTOCOLS) && if ((range_type & SCAN_PROTOCOLS) &&
nmap_getprotbynum(htons(rangestart))) { nmap_getprotbynum(htons(rangestart))) {
ports->prot_count++;
porttbl[rangestart] |= SCAN_PROTOCOLS; porttbl[rangestart] |= SCAN_PROTOCOLS;
} }
} else { } else {
if (range_type & SCAN_TCP_PORT)
ports->tcp_count++;
if (range_type & SCAN_UDP_PORT)
ports->udp_count++;
if (range_type & SCAN_PROTOCOLS && rangestart < 256)
ports->prot_count++;
porttbl[rangestart] |= range_type; porttbl[rangestart] |= range_type;
} }
} }

View File

@@ -190,7 +190,7 @@ static int nmap_protocols_init() {
*/ */
int addprotocolsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports) { int addprotocolsfromservmask(char *mask, u8 *porttbl) {
struct protocol_list *current; struct protocol_list *current;
int bucket, t=0; int bucket, t=0;
@@ -201,7 +201,6 @@ int addprotocolsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports)
for(current = protocol_table[bucket % PROTOCOL_TABLE_SIZE]; current; current = current->next) { for(current = protocol_table[bucket % PROTOCOL_TABLE_SIZE]; current; current = current->next) {
if (wildtest(mask, current->protoent->p_name)) { if (wildtest(mask, current->protoent->p_name)) {
porttbl[ntohs(current->protoent->p_proto)] |= SCAN_PROTOCOLS; porttbl[ntohs(current->protoent->p_proto)] |= SCAN_PROTOCOLS;
ports->prot_count++;
t++; t++;
} }
} }

View File

@@ -117,7 +117,7 @@ struct protocol_list {
struct protocol_list *next; struct protocol_list *next;
}; };
int addprotocolsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports); int addprotocolsfromservmask(char *mask, u8 *porttbl);
struct protoent *nmap_getprotbynum(int num); struct protoent *nmap_getprotbynum(int num);
#endif #endif

View File

@@ -272,7 +272,7 @@ static int nmap_services_init() {
* Returns the number of ports added in total. * Returns the number of ports added in total.
*/ */
int addportsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports, int range_type) { int addportsfromservmask(char *mask, u8 *porttbl, int range_type) {
struct service_list *current; struct service_list *current;
int bucket,t=0; int bucket,t=0;
@@ -285,13 +285,11 @@ int addportsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports, int
if ((range_type & SCAN_TCP_PORT) && strcmp(current->servent->s_proto, "tcp") == 0) { if ((range_type & SCAN_TCP_PORT) && strcmp(current->servent->s_proto, "tcp") == 0) {
porttbl[ntohs(current->servent->s_port)] |= SCAN_TCP_PORT; porttbl[ntohs(current->servent->s_port)] |= SCAN_TCP_PORT;
ports->tcp_count++;
t++; t++;
} }
if ((range_type & SCAN_UDP_PORT) && strcmp(current->servent->s_proto, "udp") == 0) { if ((range_type & SCAN_UDP_PORT) && strcmp(current->servent->s_proto, "udp") == 0) {
porttbl[ntohs(current->servent->s_port)] |= SCAN_UDP_PORT; porttbl[ntohs(current->servent->s_port)] |= SCAN_UDP_PORT;
ports->udp_count++;
t++; t++;
} }

View File

@@ -128,7 +128,7 @@ struct service_list {
struct service_list *next; struct service_list *next;
}; };
int addportsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports, int range_type); int addportsfromservmask(char *mask, u8 *porttbl, int range_type);
struct servent *nmap_getservbyport(int port, const char *proto); struct servent *nmap_getservbyport(int port, const char *proto);
struct scan_lists *gettoppts(double level, char *portlist); struct scan_lists *gettoppts(double level, char *portlist);