mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 08:46:45 +00:00
Allow cleanup of netutil's interfaces cache
This commit is contained in:
parent
e20093b16d
commit
2cea59aca0
3 changed files with 10 additions and 4 deletions
|
|
@ -1391,6 +1391,7 @@ static struct interface_info *getinterfaces_dnet(int *howmany, char *errstr, siz
|
|||
return dcrn.ifaces;
|
||||
}
|
||||
|
||||
static struct interface_info *mydevs = NULL;
|
||||
/* Returns an allocated array of struct interface_info representing the
|
||||
available interfaces. The number of interfaces is returned in *howmany. This
|
||||
function just does caching of results; the real work is done in
|
||||
|
|
@ -1398,13 +1399,10 @@ static struct interface_info *getinterfaces_dnet(int *howmany, char *errstr, siz
|
|||
On error, NULL is returned, howmany is set to -1 and the supplied
|
||||
error buffer "errstr", if not NULL, will contain an error message. */
|
||||
struct interface_info *getinterfaces(int *howmany, char *errstr, size_t errstrlen) {
|
||||
static int initialized = 0;
|
||||
static struct interface_info *mydevs;
|
||||
static int numifaces = 0;
|
||||
|
||||
if (!initialized) {
|
||||
if (mydevs == NULL) {
|
||||
mydevs = getinterfaces_dnet(&numifaces, errstr, errstrlen);
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
/* These will propagate any error produced in getinterfaces_xxxx() to
|
||||
|
|
@ -1414,6 +1412,10 @@ struct interface_info *getinterfaces(int *howmany, char *errstr, size_t errstrle
|
|||
return mydevs;
|
||||
}
|
||||
|
||||
void freeinterfaces(void) {
|
||||
free(mydevs);
|
||||
mydevs = NULL;
|
||||
}
|
||||
|
||||
/* The 'dev' passed in must be at least 32 bytes long. Returns 0 on success. */
|
||||
int ipaddr2devname(char *dev, const struct sockaddr_storage *addr) {
|
||||
|
|
|
|||
|
|
@ -337,6 +337,9 @@ int sockaddr_equal_zero(const struct sockaddr_storage *s);
|
|||
On error, NULL is returned, howmany is set to -1 and the supplied
|
||||
error buffer "errstr", if not NULL, will contain an error message. */
|
||||
struct interface_info *getinterfaces(int *howmany, char *errstr, size_t errstrlen);
|
||||
/* Frees the array of cached struct interface_info used by getinterfaces. Can
|
||||
be used to force a refresh or to release memory. */
|
||||
void freeinterfaces(void);
|
||||
|
||||
/* This struct is abused to carry either routes or interfaces, depending on the
|
||||
function it's used in. */
|
||||
|
|
|
|||
1
nmap.cc
1
nmap.cc
|
|
@ -1788,6 +1788,7 @@ void nmap_free_mem() {
|
|||
PortList::freePortMap();
|
||||
cp_free();
|
||||
free_services();
|
||||
freeinterfaces();
|
||||
AllProbes::service_scan_free();
|
||||
traceroute_hop_cache_clear();
|
||||
nsock_set_default_engine(NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue