"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/ifinfo.c" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

ifinfo.c  (vnstat-2.7):ifinfo.c  (vnstat-2.8)
#include "common.h" #include "common.h"
#include "ibw.h"
#include "ifinfo.h" #include "ifinfo.h"
int getifinfo(const char *iface) int getifinfo(const char *iface)
{ {
char inface[32]; char inface[32];
ifinfo.filled = 0; ifinfo.filled = 0;
ifinfo.timestamp = 0; ifinfo.timestamp = 0;
#if defined(__linux__) #if defined(__linux__) && HAVE_LINUX_RTNETLINK_H
if (cfg.is64bit == -2) { if (cfg.is64bit == -2) {
#if HAVE_DECL_IFLA_STATS64 #if HAVE_DECL_IFLA_STATS64
ifinfo.is64bit = 1; ifinfo.is64bit = 1;
#else #else
ifinfo.is64bit = 0; ifinfo.is64bit = 0;
#endif #endif
} else { } else {
ifinfo.is64bit = (short)cfg.is64bit; ifinfo.is64bit = (short)cfg.is64bit;
} }
#else #else
skipping to change at line 109 skipping to change at line 110
iflistfree(&ifl); iflistfree(&ifl);
return 1; return 1;
} }
iflistfree(&ifl); iflistfree(&ifl);
return 0; return 0;
} }
int getiflist(iflist **ifl, const int getspeed, const int validate) int getiflist(iflist **ifl, const int getspeed, const int validate)
{ {
int result = 0;
int32_t maxbw = cfg.maxbw;
/* disable MaxBandwidth during list creation to avoid having it being set
as the default value when nothing is detected */
cfg.maxbw = 0;
#if defined(__linux__) || defined(CHECK_VNSTAT) #if defined(__linux__) || defined(CHECK_VNSTAT)
return getiflist_linux(ifl, getspeed, validate); result = getiflist_linux(ifl, getspeed, validate);
#elif defined(BSD_VNSTAT) #elif defined(BSD_VNSTAT)
return getiflist_bsd(ifl, getspeed, validate); result = getiflist_bsd(ifl, getspeed, validate);
#else #else
#error vnStat only supports Linux and BSD like systems #error vnStat only supports Linux and BSD like systems
#endif #endif
cfg.maxbw = maxbw;
return result;
} }
#if defined(__linux__) || defined(CHECK_VNSTAT) #if defined(__linux__) || defined(CHECK_VNSTAT)
int getiflist_linux(iflist **ifl, const int getspeed, const int validate) int getiflist_linux(iflist **ifl, const int getspeed, const int validate)
{ {
char temp[64]; char temp[64];
char interface[32]; char interface[32];
FILE *fp; FILE *fp;
DIR *dp; DIR *dp;
struct dirent *di; struct dirent *di;
char procline[512]; char procline[512];
uint32_t bwlimit = 0;
if ((fp = fopen(PROCNETDEV, "r")) != NULL) { if ((fp = fopen(PROCNETDEV, "r")) != NULL) {
/* make list of interfaces */ /* make list of interfaces */
while (fgets(procline, 512, fp) != NULL) { while (fgets(procline, 512, fp) != NULL) {
sscanf(procline, "%63s", temp); sscanf(procline, "%63s", temp);
if (strlen(temp) > 0 && (isdigit(temp[(strlen(temp) - 1)] ) || temp[(strlen(temp) - 1)] == ':')) { if (strlen(temp) > 0 && (isdigit(temp[(strlen(temp) - 1)] ) || temp[(strlen(temp) - 1)] == ':')) {
sscanf(temp, "%31[^':']s", interface); sscanf(temp, "%31[^':']s", interface);
if (validate && !isifvalid(interface)) { if (validate && !isifvalid(interface)) {
continue; continue;
} }
if (getspeed) { bwlimit = 0;
iflistadd(ifl, interface, getifspeed(inte if (getspeed && ibwget(interface, &bwlimit)) {
rface)); iflistadd(ifl, interface, bwlimit);
} else { } else {
iflistadd(ifl, interface, 0); iflistadd(ifl, interface, 0);
} }
} }
} }
fclose(fp); fclose(fp);
return 1; return 1;
} else { } else {
skipping to change at line 161 skipping to change at line 171
if ((dp = opendir(SYSCLASSNET)) != NULL) { if ((dp = opendir(SYSCLASSNET)) != NULL) {
/* make list of interfaces */ /* make list of interfaces */
while ((di = readdir(dp))) { while ((di = readdir(dp))) {
if (di->d_name[0] == '.' || strlen(di->d_name) > 31) { if (di->d_name[0] == '.' || strlen(di->d_name) > 31) {
continue; continue;
} }
if (validate && !isifvalid(di->d_name)) { if (validate && !isifvalid(di->d_name)) {
continue; continue;
} }
if (getspeed) { bwlimit = 0;
iflistadd(ifl, di->d_name, getifspeed(di- if (getspeed && ibwget(di->d_name, &bwlimit)) {
>d_name)); iflistadd(ifl, di->d_name, bwlimit);
} else { } else {
iflistadd(ifl, di->d_name, 0); iflistadd(ifl, di->d_name, 0);
} }
} }
closedir(dp); closedir(dp);
return 1; return 1;
} }
} }
return 0; return 0;
} }
#elif defined(BSD_VNSTAT) #elif defined(BSD_VNSTAT)
int getiflist_bsd(iflist **ifl, const int getspeed, const int validate) int getiflist_bsd(iflist **ifl, const int getspeed, const int validate)
{ {
struct ifaddrs *ifap, *ifa; struct ifaddrs *ifap, *ifa;
uint32_t bwlimit = 0;
if (getifaddrs(&ifap) >= 0) { if (getifaddrs(&ifap) >= 0) {
/* make list of interfaces */ /* make list of interfaces */
for (ifa = ifap; ifa; ifa = ifa->ifa_next) { for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family != AF_LINK || strlen(ifa->if a_name) > 31) { if (ifa->ifa_addr->sa_family != AF_LINK || strlen(ifa->if a_name) > 31) {
continue; continue;
} }
if (validate && !isifvalid(ifa->ifa_name)) { if (validate && !isifvalid(ifa->ifa_name)) {
continue; continue;
} }
if (getspeed) { bwlimit = 0;
if (getspeed && ibwget(ifa->ifa_name, &bwlimit)) {
iflistadd(ifl, ifa->ifa_name, getifspeed(ifa->ifa _name)); iflistadd(ifl, ifa->ifa_name, getifspeed(ifa->ifa _name));
} else { } else {
iflistadd(ifl, ifa->ifa_name, 0); iflistadd(ifl, ifa->ifa_name, 0);
} }
} }
freeifaddrs(ifap); freeifaddrs(ifap);
return 1; return 1;
} }
skipping to change at line 473 skipping to change at line 486
return 0; return 0;
} else if (strcmp(iface, "lo") == 0) { } else if (strcmp(iface, "lo") == 0) {
return 0; return 0;
} else if (strcmp(iface, "lo0") == 0) { } else if (strcmp(iface, "lo0") == 0) {
return 0; return 0;
} else if (strcmp(iface, "sit0") == 0) { } else if (strcmp(iface, "sit0") == 0) {
return 0; return 0;
} }
return 1; return 1;
} }
/* tun interfaces have speed hardcoded as 10 in the Linux kernel regardless of u
sed interface and can't
be trusted to provide correct details as a result even if the information is ava
ilable:
https://github.com/torvalds/linux/blob/9d31d2338950293ec19d9b095fbaa9030899dcb4/
drivers/net/tun.c#L3456 */
int istun(const char *iface)
{
#if defined(__linux__)
if (strlen(iface) > 3 && strncmp(iface, "tun", 3) == 0) {
if (isdigit(iface[3])) {
return 1;
}
}
#endif
return 0;
}
 End of changes. 12 change blocks. 
10 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)