extern int if_fetch(struct interface *ife);
extern int for_all_interfaces(int (*)(struct interface *, void *), void *);
-extern int free_interface_list(void);
+extern int if_cache_free(void);
extern struct interface *lookup_interface(char *name);
extern int if_readlist(void);
8/2000 Andi Kleen make the list operations a bit more efficient.
People are crazy enough to use thousands of aliases now.
- $Id: interface.c,v 1.20 2001/11/24 05:23:35 ecki Exp $
+ $Id: interface.c,v 1.21 2001/11/25 06:48:51 ecki Exp $
*/
#include "config.h"
static int if_readlist_proc(char *);
-static struct interface *add_interface(char *name)
+static struct interface *if_cache_add(char *name)
{
struct interface *ife, **nextp, *new;
+ if (!int_list)
+ int_last = NULL;
+
for (ife = int_last; ife; ife = ife->prev) {
int n = nstrcmp(ife->name, name);
if (n == 0)
if (if_readlist_proc(name) < 0)
return NULL;
- ife = add_interface(name);
+ ife = if_cache_add(name);
return ife;
}
return 0;
}
-int free_interface_list(void)
+int if_cache_free(void)
{
struct interface *ife;
while ((ife = int_list) != NULL) {
int_list = ife->next;
free(ife);
}
+ int_last = NULL;
return 0;
}
ifr = ifc.ifc_req;
for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) {
- add_interface(ifr->ifr_name);
+ if_cache_add(ifr->ifr_name);
ifr++;
}
err = 0;
static int if_readlist_proc(char *target)
{
- static int proc_read;
FILE *fh;
char buf[512];
struct interface *ife;
int err;
- if (proc_read)
- return 0;
- if (!target)
- proc_read = 1;
-
fh = fopen(_PATH_PROCNET_DEV, "r");
if (!fh) {
fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
while (fgets(buf, sizeof buf, fh)) {
char *s, name[IFNAMSIZ];
s = get_name(name, buf);
- ife = add_interface(name);
+ ife = if_cache_add(name);
get_dev_fields(s, ife);
ife->statistics_valid = 1;
if (target && !strcmp(target,name))
if (ferror(fh)) {
perror(_PATH_PROCNET_DEV);
err = -1;
- proc_read = 0;
}
#if 0
int if_readlist(void)
{
+ /* caller will/should check not to call this too often
+ * (i.e. only if int_list!= NULL
+ */
int err = if_readlist_proc(NULL);
if (!err)
err = if_readconf();
* NET-3 Networking Distribution for the LINUX operating
* system.
*
- * Version: $Id: netstat.c,v 1.44 2001/08/26 05:25:21 ak Exp $
+ * Version: $Id: netstat.c,v 1.45 2001/11/25 06:48:50 ecki Exp $
*
* Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
exit(1);
}
if (flag_cnt)
- free_interface_list();
+ if_cache_free();
else {
close(skfd);
skfd = -1;