mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 21:21:31 +00:00
Allow cleanup of netutil's interfaces cache
This commit is contained in:
@@ -1391,6 +1391,7 @@ static struct interface_info *getinterfaces_dnet(int *howmany, char *errstr, siz
|
|||||||
return dcrn.ifaces;
|
return dcrn.ifaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct interface_info *mydevs = NULL;
|
||||||
/* Returns an allocated array of struct interface_info representing the
|
/* Returns an allocated array of struct interface_info representing the
|
||||||
available interfaces. The number of interfaces is returned in *howmany. This
|
available interfaces. The number of interfaces is returned in *howmany. This
|
||||||
function just does caching of results; the real work is done in
|
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
|
On error, NULL is returned, howmany is set to -1 and the supplied
|
||||||
error buffer "errstr", if not NULL, will contain an error message. */
|
error buffer "errstr", if not NULL, will contain an error message. */
|
||||||
struct interface_info *getinterfaces(int *howmany, char *errstr, size_t errstrlen) {
|
struct interface_info *getinterfaces(int *howmany, char *errstr, size_t errstrlen) {
|
||||||
static int initialized = 0;
|
|
||||||
static struct interface_info *mydevs;
|
|
||||||
static int numifaces = 0;
|
static int numifaces = 0;
|
||||||
|
|
||||||
if (!initialized) {
|
if (mydevs == NULL) {
|
||||||
mydevs = getinterfaces_dnet(&numifaces, errstr, errstrlen);
|
mydevs = getinterfaces_dnet(&numifaces, errstr, errstrlen);
|
||||||
initialized = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* These will propagate any error produced in getinterfaces_xxxx() to
|
/* 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;
|
return mydevs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freeinterfaces(void) {
|
||||||
|
free(mydevs);
|
||||||
|
mydevs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* The 'dev' passed in must be at least 32 bytes long. Returns 0 on success. */
|
/* The 'dev' passed in must be at least 32 bytes long. Returns 0 on success. */
|
||||||
int ipaddr2devname(char *dev, const struct sockaddr_storage *addr) {
|
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
|
On error, NULL is returned, howmany is set to -1 and the supplied
|
||||||
error buffer "errstr", if not NULL, will contain an error message. */
|
error buffer "errstr", if not NULL, will contain an error message. */
|
||||||
struct interface_info *getinterfaces(int *howmany, char *errstr, size_t errstrlen);
|
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
|
/* This struct is abused to carry either routes or interfaces, depending on the
|
||||||
function it's used in. */
|
function it's used in. */
|
||||||
|
|||||||
1
nmap.cc
1
nmap.cc
@@ -1788,6 +1788,7 @@ void nmap_free_mem() {
|
|||||||
PortList::freePortMap();
|
PortList::freePortMap();
|
||||||
cp_free();
|
cp_free();
|
||||||
free_services();
|
free_services();
|
||||||
|
freeinterfaces();
|
||||||
AllProbes::service_scan_free();
|
AllProbes::service_scan_free();
|
||||||
traceroute_hop_cache_clear();
|
traceroute_hop_cache_clear();
|
||||||
nsock_set_default_engine(NULL);
|
nsock_set_default_engine(NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user