2 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
3 * author: Gleb Smirnoff <glebius@FreeBSD.org>
4 * (c) 2006 Ryan Wagoner
5 * (c) 2014 Gleb Smirnoff
6 * This software is subject to the conditions detailed
7 * in the LICENCE file provided within the distribution */
10 #include <sys/socket.h>
17 #ifdef ENABLE_GETIFSTATS_CACHING
21 #include "../getifstats.h"
22 #include "../config.h"
25 getifstats(const char *ifname
, struct ifdata
*data
)
27 static struct ifaddrs
*ifap
, *ifa
;
28 #ifdef ENABLE_GETIFSTATS_CACHING
29 static time_t cache_timestamp
;
34 data
->baudrate
= 4200000;
39 if(!ifname
|| ifname
[0]=='\0')
42 #ifdef ENABLE_GETIFSTATS_CACHING
43 current_time
= time(NULL
);
45 current_time
< cache_timestamp
+ GETIFSTATS_CACHING_DURATION
)
54 if (getifaddrs(&ifap
) != 0) {
55 syslog (LOG_ERR
, "getifstats() : getifaddrs(): %s",
60 for (ifa
= ifap
; ifa
; ifa
= ifa
->ifa_next
)
61 if (ifa
->ifa_addr
->sa_family
== AF_LINK
&&
62 strcmp(ifa
->ifa_name
, ifname
) == 0) {
63 #ifdef ENABLE_GETIFSTATS_CACHING
64 cache_timestamp
= current_time
;
67 #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
68 data
->opackets
= IFA_STAT(opackets
);
69 data
->ipackets
= IFA_STAT(ipackets
);
70 data
->obytes
= IFA_STAT(obytes
);
71 data
->ibytes
= IFA_STAT(ibytes
);
72 data
->baudrate
= IFA_STAT(baudrate
);