diff -urNb nmap-3.81/nmap.cc nmap-3.81-factored/nmap.cc --- nmap-3.81/nmap.cc 2005-06-07 21:34:44.685973784 -0700 +++ nmap-3.81-factored/nmap.cc 2005-06-07 21:35:09.447209504 -0700 @@ -798,23 +798,25 @@ fatal("The fast scan (-F) is incompatible with ping scan"); } + // Fast (-F) port/prot lists if (fastscan && ports) { fatal("You can specify fast scan (-F) or explicitly select individual ports (-p), but not both"); } else if (fastscan && o.ipprotscan) { - ports = getfastprots(); + ports = getpts("[P:0-]"); } else if (fastscan) { - ports = getfastports(o.TCPScan(), o.UDPScan()); + ports = getpts("[-]"); } if ((o.pingscan || o.listscan) && ports) { fatal("You cannot use -F (fast scan) or -p (explicit port selection) with PING scan or LIST scan"); } + // Default port/prot lists if (!ports) { if (o.ipprotscan) { - ports = getdefaultprots(); + ports = getpts("0-"); } else { - ports = getdefaultports(o.TCPScan(), o.UDPScan()); + ports = getpts("1-1024,[1025-]"); } } diff -urNb nmap-3.81/protocols.cc nmap-3.81-factored/protocols.cc --- nmap-3.81/protocols.cc 2005-06-07 21:34:44.686973632 -0700 +++ nmap-3.81-factored/protocols.cc 2005-06-07 21:35:27.062531568 -0700 @@ -227,67 +227,3 @@ return NULL; } - -/* Be default we do all prots 0-255. */ -struct scan_lists *getdefaultprots(void) { - int protindex = 0; - struct scan_lists *scanlist; - /*struct protocol_list *current;*/ - int bucket; - int protsneeded = 256; - - if (!protocols_initialized) - if (nmap_protocols_init() == -1) - fatal("getdefaultprots(): Couldn't get protocol numbers"); - - scanlist = (struct scan_lists *) safe_zalloc(sizeof(struct scan_lists)); - scanlist->prots = (unsigned short *) safe_zalloc((protsneeded) * sizeof(unsigned short)); - scanlist->prot_count = protsneeded; - - for(bucket = 0; bucket < protsneeded; bucket++) { - scanlist->prots[protindex++] = bucket; - } - return scanlist; -} - -struct scan_lists *getfastprots(void) { - int protindex = 0; - struct scan_lists *scanlist; - char usedprots[256]; - struct protocol_list *current; - int bucket; - int protsneeded = 0; - - if (!protocols_initialized) - if (nmap_protocols_init() == -1) - fatal("Getfastprots: Couldn't get protocol numbers"); - - memset(usedprots, 0, sizeof(usedprots)); - - for(bucket = 0; bucket < PROTOCOL_TABLE_SIZE; bucket++) { - for(current = protocol_table[bucket % PROTOCOL_TABLE_SIZE]; - current; current = current->next) { - if (!usedprots[ntohs(current->protoent->p_proto)]) - usedprots[ntohs(current->protoent->p_proto)] = 1; - protsneeded++; - } - } - - scanlist = (struct scan_lists *) safe_zalloc(sizeof(struct scan_lists)); - scanlist->prots = (unsigned short *) safe_zalloc((protsneeded ) * sizeof(unsigned short)); - scanlist->prot_count = protsneeded; - - for(bucket = 0; bucket < 256; bucket++) { - if (usedprots[bucket]) - scanlist->prots[protindex++] = bucket; - } - - return scanlist; -} - - - - - - - diff -urNb nmap-3.81/protocols.h nmap-3.81-factored/protocols.h --- nmap-3.81/protocols.h 2005-06-07 21:34:44.687973480 -0700 +++ nmap-3.81-factored/protocols.h 2005-06-07 21:35:31.028928584 -0700 @@ -121,8 +121,5 @@ int addprotocolsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports); struct protoent *nmap_getprotbynum(int num); -struct scan_lists *getfastprots(void); -struct scan_lists *getdefaultprots(void); - #endif diff -urNb nmap-3.81/services.cc nmap-3.81-factored/services.cc --- nmap-3.81/services.cc 2005-06-07 21:34:44.688973328 -0700 +++ nmap-3.81-factored/services.cc 2005-06-07 21:35:21.179425936 -0700 @@ -274,123 +274,3 @@ return NULL; } - -/* Be default we do all ports 1-1024 as well as any higher ports - that are in the services file */ -struct scan_lists *getdefaultports(int tcpscan, int udpscan) { - int tcpportindex = 0; - int udpportindex = 0; - struct scan_lists *ports; - u8 *usedports; - struct service_list *current; - int bucket; - int tcpportsneeded = 0; - int udpportsneeded = 0; - - if (!services_initialized) - if (nmap_services_init() == -1) - fatal("Getfastports: Couldn't get port numbers"); - - usedports = (u8 *) safe_zalloc(sizeof(*usedports) * 65536); - - for(bucket = 1; bucket < 1025; bucket++) { - if (tcpscan) { - usedports[bucket] |= SCAN_TCP_PORT; - tcpportsneeded++; - } - if (udpscan) { - usedports[bucket] |= SCAN_UDP_PORT; - udpportsneeded++; - } - } - - for(bucket = 0; bucket < SERVICE_TABLE_SIZE; bucket++) { - for(current = service_table[bucket % SERVICE_TABLE_SIZE]; - current; current = current->next) { - if (tcpscan && - ! (usedports[ntohs(current->servent->s_port)] & SCAN_TCP_PORT) && - ! strncmp(current->servent->s_proto, "tcp", 3)) { - usedports[ntohs(current->servent->s_port)] |= SCAN_TCP_PORT; - tcpportsneeded++; - } - if (udpscan && - ! (usedports[ntohs(current->servent->s_port)] & SCAN_UDP_PORT) && - !strncmp(current->servent->s_proto, "udp", 3)) { - usedports[ntohs(current->servent->s_port)] |= SCAN_UDP_PORT; - udpportsneeded++; - } - } - } - - ports = (struct scan_lists *) safe_zalloc(sizeof(struct scan_lists)); - if (tcpscan) - ports->tcp_ports = (unsigned short *) safe_zalloc((tcpportsneeded) * sizeof(unsigned short)); - if (udpscan) - ports->udp_ports = (unsigned short *) safe_zalloc((udpportsneeded) * sizeof(unsigned short)); - ports->tcp_count= tcpportsneeded; - ports->udp_count= udpportsneeded; - - for(bucket = 0; bucket < 65536; bucket++) { - if (usedports[bucket] & SCAN_TCP_PORT) - ports->tcp_ports[tcpportindex++] = bucket; - if (usedports[bucket] & SCAN_UDP_PORT) - ports->udp_ports[udpportindex++] = bucket; - } - - free(usedports); - return ports; -} - -struct scan_lists *getfastports(int tcpscan, int udpscan) { - int tcpportindex = 0; - int udpportindex = 0; - struct scan_lists *ports; - u8 *usedports; - struct service_list *current; - int bucket; - int tcpportsneeded = 0; - int udpportsneeded = 0; - - if (!services_initialized) - if (nmap_services_init() == -1) - fatal("Getfastports: Couldn't get port numbers"); - - usedports = (u8 *) safe_zalloc(sizeof(*usedports) * 65536); - - for(bucket = 0; bucket < SERVICE_TABLE_SIZE; bucket++) { - for(current = service_table[bucket % SERVICE_TABLE_SIZE]; - current; current = current->next) { - if (tcpscan && - ! (usedports[ntohs(current->servent->s_port)] & SCAN_TCP_PORT) && - !strncmp(current->servent->s_proto, "tcp", 3)) { - usedports[ntohs(current->servent->s_port)] |= SCAN_TCP_PORT; - tcpportsneeded++; - } - if (udpscan && - ! (usedports[ntohs(current->servent->s_port)] & SCAN_UDP_PORT) && - !strncmp(current->servent->s_proto, "udp", 3)) { - usedports[ntohs(current->servent->s_port)] |= SCAN_UDP_PORT; - udpportsneeded++; - } - } - } - - ports = (struct scan_lists *) safe_zalloc(sizeof(struct scan_lists)); - if (tcpscan) - ports->tcp_ports = (unsigned short *) safe_zalloc((tcpportsneeded) * sizeof(unsigned short)); - if (udpscan) - ports->udp_ports = (unsigned short *) safe_zalloc((udpportsneeded) * sizeof(unsigned short)); - ports->tcp_count= tcpportsneeded; - ports->udp_count= udpportsneeded; - - for(bucket = 0; bucket < 65536; bucket++) { - if (usedports[bucket] & SCAN_TCP_PORT) - ports->tcp_ports[tcpportindex++] = bucket; - if (usedports[bucket] & SCAN_UDP_PORT) - ports->udp_ports[udpportindex++] = bucket; - } - - free(usedports); - return ports; -} - diff -urNb nmap-3.81/services.h nmap-3.81-factored/services.h --- nmap-3.81/services.h 2005-06-07 21:34:44.689973176 -0700 +++ nmap-3.81-factored/services.h 2005-06-07 21:35:23.303103088 -0700 @@ -130,7 +130,5 @@ int addportsfromservmask(char *mask, u8 *porttbl, struct scan_lists *ports, int range_type); struct servent *nmap_getservbyport(int port, const char *proto); -struct scan_lists *getfastports(int tcpscan, int udpscan); -struct scan_lists *getdefaultports(int tcpscan, int udpscan); #endif