1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-15 20:29:03 +00:00

Improve the efficiency of loading the nmap-services file. We now use an STL map

instead of a custom hash table and an STL list instead of a custom linked list.
The biggest gain comes from using the list.sort method rather than inserting
ports in sorted order (equivalent to insertion sort). The new code passes
Doug's p-switch-tests.

Here are time comparisons, using the old and new services code, and using the
standard nmap-services file and the 65535-port nmap-services-huge. The times
are the duration of the call to nmap_services_init. Three trials were done for
each case, except for the old-code/nmap-services-huge case.

nmap-services:
old code:   0.215  0.201  0.227  (average   0.214 s)
new code:   0.025  0.022  0.023  (average   0.023 s)

nmap-services-huge:
old code: 441.014                (average 441.014 s)
new code:   0.984  0.975  0.978  (average   0.979 s)
This commit is contained in:
david
2008-08-13 01:19:09 +00:00
parent 931285f765
commit 3a67da3a7e
2 changed files with 127 additions and 121 deletions

View File

@@ -122,12 +122,6 @@
#define SCAN_UDP_PORT (1 << 1)
#define SCAN_PROTOCOLS (1 << 2)
struct service_list {
struct servent *servent;
double ratio;
struct service_list *next;
};
int addportsfromservmask(char *mask, u8 *porttbl, int range_type);
struct servent *nmap_getservbyport(int port, const char *proto);
void gettoppts(double level, char *portlist, struct scan_lists * ports);