mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +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;
|
||||
}
|
||||
|
||||
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. */
|
||||
|
||||
Reference in New Issue
Block a user