- 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 <admin su29 net> [1] PR: bin/119581 MFC after: 2 weeks
This commit is contained in:
parent
b3c56ffc39
commit
5abb148f43
@ -37,6 +37,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user