version 1.1, 2012/02/21 23:16:02
|
version 1.1.1.2, 2012/05/29 12:55:57
|
Line 1
|
Line 1
|
/* $Id$ */ |
/* $Id$ */ |
/* MiniUPnP project |
/* MiniUPnP project |
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
* (c) 2006,2007 Thomas Bernard | * (c) 2006-2011 Thomas Bernard |
* 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 11
|
Line 11
|
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
|
|
#include "../getifstats.h" |
|
#include "../config.h" |
#include "../config.h" |
|
#include "../getifstats.h" |
|
|
int |
int |
getifstats(const char * ifname, struct ifdata * data) |
getifstats(const char * ifname, struct ifdata * data) |
Line 22 getifstats(const char * ifname, struct ifdata * data)
|
Line 22 getifstats(const char * ifname, struct ifdata * data)
|
char * p; |
char * p; |
int i; |
int i; |
int r = -1; |
int r = -1; |
|
char fname[64]; |
#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 29 getifstats(const char * ifname, struct ifdata * data)
|
Line 30 getifstats(const char * ifname, struct ifdata * data)
|
#endif |
#endif |
if(!data) |
if(!data) |
return -1; |
return -1; |
data->baudrate = 4200000; | data->baudrate = 4200000; /* that is the answer */ |
data->opackets = 0; |
data->opackets = 0; |
data->ipackets = 0; |
data->ipackets = 0; |
data->obytes = 0; |
data->obytes = 0; |
Line 42 getifstats(const char * ifname, struct ifdata * data)
|
Line 43 getifstats(const char * ifname, struct ifdata * data)
|
syslog(LOG_ERR, "getifstats() : time() error : %m"); |
syslog(LOG_ERR, "getifstats() : time() error : %m"); |
} else { |
} else { |
if(current_time < cache_timestamp + GETIFSTATS_CACHING_DURATION) { |
if(current_time < cache_timestamp + GETIFSTATS_CACHING_DURATION) { |
|
/* return cached data */ |
memcpy(data, &cache_data, sizeof(struct ifdata)); |
memcpy(data, &cache_data, sizeof(struct ifdata)); |
return 0; |
return 0; |
} |
} |
Line 84 getifstats(const char * ifname, struct ifdata * data)
|
Line 86 getifstats(const char * ifname, struct ifdata * data)
|
break; |
break; |
} |
} |
fclose(f); |
fclose(f); |
|
/* get interface speed */ |
|
snprintf(fname, sizeof(fname), "/sys/class/net/%s/speed", ifname); |
|
f = fopen(fname, "r"); |
|
if(f) { |
|
if(fgets(line, sizeof(line), f)) { |
|
data->baudrate = 1000000*atoi(line); |
|
} |
|
fclose(f); |
|
} else { |
|
syslog(LOG_WARNING, "cannot read %s file : %m", fname); |
|
} |
#ifdef ENABLE_GETIFSTATS_CACHING |
#ifdef ENABLE_GETIFSTATS_CACHING |
if(r==0 && current_time!=((time_t)-1)) { |
if(r==0 && current_time!=((time_t)-1)) { |
|
/* cache the new data */ |
cache_timestamp = current_time; |
cache_timestamp = current_time; |
memcpy(&cache_data, data, sizeof(struct ifdata)); |
memcpy(&cache_data, data, sizeof(struct ifdata)); |
} |
} |