version 1.1.1.1, 2012/02/21 23:16:02
|
version 1.1.1.2, 2012/05/29 12:55:57
|
Line 1
|
Line 1
|
|
/* $Id$ */ |
/* |
/* |
* MiniUPnP project |
* MiniUPnP project |
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
* (c) 2009 Jarder Weyrich | * (c) 2009 Jardel Weyrich |
* This software is subject to the conditions detailed |
* This software is subject to the conditions detailed |
* in the LICENCE file provided within the distribution |
* in the LICENCE file provided within the distribution |
*/ |
*/ |
Line 25 int getifstats(const char * ifname, struct ifdata * da
|
Line 26 int getifstats(const char * ifname, struct ifdata * da
|
int mib[] = { CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_IFLIST, if_nametoindex(ifname) }; |
int mib[] = { CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_IFLIST, if_nametoindex(ifname) }; |
const size_t mib_len = sizeof(mib) / sizeof(mib[0]); |
const size_t mib_len = sizeof(mib) / sizeof(mib[0]); |
size_t needed; |
size_t needed; |
char *buf, *end; | 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 |
Line 67 int getifstats(const char * ifname, struct ifdata * da
|
Line 68 int getifstats(const char * ifname, struct ifdata * da
|
free(buf); |
free(buf); |
return -1; // error |
return -1; // error |
} else { |
} else { |
for (end = buf + needed; buf < end; buf += ifm->ifm_msglen) { | for (end = buf + needed, p = buf; p < end; p += ifm->ifm_msglen) { |
ifm = (struct if_msghdr *) buf; | ifm = (struct if_msghdr *) p; |
if (ifm->ifm_type == RTM_IFINFO && ifm->ifm_data.ifi_type == IFT_ETHER) { |
if (ifm->ifm_type == RTM_IFINFO && ifm->ifm_data.ifi_type == IFT_ETHER) { |
ifdata = ifm->ifm_data; |
ifdata = ifm->ifm_data; |
data->opackets = ifdata.ifi_opackets; |
data->opackets = ifdata.ifi_opackets; |