version 1.1.1.2, 2012/05/29 12:55:57
|
version 1.1.1.3, 2013/07/22 00:32:35
|
Line 28 int getifstats(const char * ifname, struct ifdata * da
|
Line 28 int getifstats(const char * ifname, struct ifdata * da
|
size_t needed; |
size_t needed; |
char *buf, *end, *p; |
char *buf, *end, *p; |
struct if_msghdr *ifm; |
struct if_msghdr *ifm; |
struct if_data ifdata; | struct if_data ifdata; |
#ifdef ENABLE_GETIFSTATS_CACHING |
#ifdef ENABLE_GETIFSTATS_CACHING |
static time_t cache_timestamp = 0; |
static time_t cache_timestamp = 0; |
static struct ifdata cache_data; |
static struct ifdata cache_data; |
Line 36 int getifstats(const char * ifname, struct ifdata * da
|
Line 36 int getifstats(const char * ifname, struct ifdata * da
|
#endif |
#endif |
|
|
if (data == NULL || ifname == NULL || ifname[0] == '\0') |
if (data == NULL || ifname == NULL || ifname[0] == '\0') |
return -1; // error | return -1; /* error */ |
|
|
data->baudrate = 4200000; |
data->baudrate = 4200000; |
data->opackets = 0; |
data->opackets = 0; |
Line 62 int getifstats(const char * ifname, struct ifdata * da
|
Line 62 int getifstats(const char * ifname, struct ifdata * da
|
} |
} |
buf = (char *) malloc(needed); |
buf = (char *) malloc(needed); |
if (buf == NULL) |
if (buf == NULL) |
return -1; // error | return -1; /* error */ |
if (sysctl(mib, mib_len, buf, &needed, NULL, 0) == -1) { |
if (sysctl(mib, mib_len, buf, &needed, NULL, 0) == -1) { |
syslog(LOG_ERR, "sysctl(): %m"); |
syslog(LOG_ERR, "sysctl(): %m"); |
free(buf); |
free(buf); |
return -1; // error | return -1; /* error */ |
} else { |
} else { |
for (end = buf + needed, p = buf; p < end; p += ifm->ifm_msglen) { |
for (end = buf + needed, p = buf; p < end; p += ifm->ifm_msglen) { |
ifm = (struct if_msghdr *) p; |
ifm = (struct if_msghdr *) p; |
Line 84 int getifstats(const char * ifname, struct ifdata * da
|
Line 84 int getifstats(const char * ifname, struct ifdata * da
|
memcpy(&cache_data, data, sizeof(struct ifdata)); |
memcpy(&cache_data, data, sizeof(struct ifdata)); |
} |
} |
#endif |
#endif |
return 0; // found, ok | return 0; /* found, ok */ |
} |
} |
} | } |
} |
} |
free(buf); |
free(buf); |
return -1; // not found or error | return -1; /* not found or error */ |
} |
} |
|
|