diff options
author | Can Erkin Acar <canacar@cvs.openbsd.org> | 2009-11-23 01:51:42 +0000 |
---|---|---|
committer | Can Erkin Acar <canacar@cvs.openbsd.org> | 2009-11-23 01:51:42 +0000 |
commit | 995f8dab19a0dbb3f780d4b0faaa5bc9830337e8 (patch) | |
tree | 839671c808eb81639153e9c88f70eb629cdb5cfd | |
parent | d35f3535dd91e047e8d26d34438cc4e0a6b1666d (diff) |
Properly handle interfaces deleted from the middle of the list.
Reported by deraadt@
-rw-r--r-- | usr.bin/systat/if.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/usr.bin/systat/if.c b/usr.bin/systat/if.c index 8590effce5b..a5d4e1bdb43 100644 --- a/usr.bin/systat/if.c +++ b/usr.bin/systat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.16 2009/08/13 23:45:35 deraadt Exp $ */ +/* $OpenBSD: if.c,v 1.17 2009/11/23 01:51:41 canacar Exp $ */ /* * Copyright (c) 2004 Markus Friedl <markus@openbsd.org> * @@ -39,6 +39,7 @@ struct ifstat { struct ifcount ifs_cur; struct ifcount ifs_old; struct ifcount ifs_now; + char ifs_flag; } *ifstats; static int nifs = 0; @@ -187,7 +188,7 @@ fetchifstat(void) struct sockaddr_dl *sdl; char *buf, *next, *lim; static int s = -1; - int mib[6]; + int mib[6], i; size_t need; mib[0] = CTL_NET; @@ -270,7 +271,18 @@ fetchifstat(void) UPDATE(ifc_co, ifm_data.ifi_collisions); ifs->ifs_cur.ifc_flags = ifm.ifm_flags; ifs->ifs_cur.ifc_state = ifm.ifm_data.ifi_link_state; + ifs->ifs_flag++; } + + /* remove unreferenced interfaces */ + for (i = 0; i < nifs; i++) { + ifs = &ifstats[i]; + if (ifs->ifs_flag) + ifs->ifs_flag = 0; + else + ifs->ifs_name[0] = '\0'; + } + free(buf); } |