mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 05:01:29 +00:00
Add comments, an assertion, and simplify the logic a bit in nmap_dns.cc.
This commit is contained in:
14
nmap_dns.cc
14
nmap_dns.cc
@@ -285,6 +285,7 @@ static std::list<request *> cname_reqs;
|
|||||||
static int total_reqs;
|
static int total_reqs;
|
||||||
static nsock_pool dnspool=NULL;
|
static nsock_pool dnspool=NULL;
|
||||||
|
|
||||||
|
/* The DNS cache, not just for entries from /etc/hosts. */
|
||||||
static std::list<host_elem *> etchosts[HASH_TABLE_SIZE];
|
static std::list<host_elem *> etchosts[HASH_TABLE_SIZE];
|
||||||
|
|
||||||
static int stat_actual, stat_ok, stat_nx, stat_sf, stat_trans, stat_dropped, stat_cname;
|
static int stat_actual, stat_ok, stat_nx, stat_sf, stat_trans, stat_dropped, stat_cname;
|
||||||
@@ -968,7 +969,6 @@ static void parse_etchosts(char *fname) {
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[2048], hname[256], ipaddrstr[16], *tp;
|
char buf[2048], hname[256], ipaddrstr[16], *tp;
|
||||||
struct in_addr ia;
|
struct in_addr ia;
|
||||||
host_elem *he;
|
|
||||||
|
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
if (fp == NULL) return; // silently is OK
|
if (fp == NULL) return; // silently is OK
|
||||||
@@ -1020,9 +1020,9 @@ bool remove_and_age(host_elem *host) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add to the dns cache. If there is no space we age and
|
/* Add to the dns cache. If there are too many entries
|
||||||
* remove the least frequently used entries until there
|
* we age and remove the least frequently used ones to
|
||||||
* is space */
|
* make more space. */
|
||||||
static void addto_etchosts(u32 ip, const char *hname) {
|
static void addto_etchosts(u32 ip, const char *hname) {
|
||||||
static u16 total_size = 0;
|
static u16 total_size = 0;
|
||||||
std::list<host_elem*>::iterator it;
|
std::list<host_elem*>::iterator it;
|
||||||
@@ -1036,8 +1036,10 @@ static void addto_etchosts(u32 ip, const char *hname) {
|
|||||||
for(i = 0; i < HASH_TABLE_SIZE; i++) {
|
for(i = 0; i < HASH_TABLE_SIZE; i++) {
|
||||||
while((it = find_if(etchosts[i].begin(), etchosts[i].end(), remove_and_age)) != etchosts[i].end()) {
|
while((it = find_if(etchosts[i].begin(), etchosts[i].end(), remove_and_age)) != etchosts[i].end()) {
|
||||||
etchosts[i].erase(it);
|
etchosts[i].erase(it);
|
||||||
if((total_size--) < HASH_TABLE_SIZE/2)
|
/* We don't want total_size to become out of sync with the actual number
|
||||||
break;
|
of entries. */
|
||||||
|
assert(total_size > 0);
|
||||||
|
total_size--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user