From 3f4eb439e29a73b7acefee30e2c2c48c3f48872f Mon Sep 17 00:00:00 2001 From: delphij Date: Sat, 12 Jan 2008 00:11:26 +0000 Subject: - Handle the case where interface from "middle" is missing by more carefully inspecting the return value from sysctl(3). [1] - Use calloc instead of malloc+memset of zero. Submitted by: Alexander Chernikov [1] PR: bin/119581 MFC after: 2 weeks --- usr.bin/systat/ifstat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'usr.bin/systat/ifstat.c') diff --git a/usr.bin/systat/ifstat.c b/usr.bin/systat/ifstat.c index 27bf9ec..62773e9 100644 --- a/usr.bin/systat/ifstat.c +++ b/usr.bin/systat/ifstat.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "systat.h" #include "extern.h" @@ -210,10 +211,9 @@ initifstat(void) SLIST_INIT(&curlist); for (i = 0; i < n; i++) { - p = (struct if_stat *)malloc(sizeof(struct if_stat)); + p = (struct if_stat *)calloc(1, sizeof(struct if_stat)); if (p == NULL) IFSTAT_ERR(1, "out of memory"); - memset((void *)p, 0, sizeof(struct if_stat)); SLIST_INSERT_HEAD(&curlist, p, link); p->if_row = i+1; getifmibdata(p->if_row, &p->if_mib); @@ -384,8 +384,8 @@ getifmibdata(int row, struct ifmibdata *data) datalen = sizeof(*data); name[4] = row; - if (sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL, - (size_t)0) != 0) + if ((sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL, + (size_t)0) != 0) && (errno != ENOENT)) IFSTAT_ERR(2, "sysctl error getting interface data"); } -- cgit v1.1