Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions plugins/net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ net_get_load_real(net_priv *c, struct net_stat *net)
{
FILE *stat;
char buf[256], *s = NULL;
char *iface = g_strdup_printf("%s:", c->iface);

stat = fopen("/proc/net/dev", "r");
if(!stat)
Expand All @@ -64,7 +65,9 @@ net_get_load_real(net_priv *c, struct net_stat *net)
if (fgets(buf, 256, stat));

while (!s && !feof(stat) && fgets(buf, 256, stat))
s = g_strrstr(buf, c->iface);
s = g_strrstr(buf, iface);
// can be multiple lines start with `c->iface` in stat file,
// so match full interface name field by matching with colon
fclose(stat);
if (!s)
return -1;
Expand All @@ -75,9 +78,11 @@ net_get_load_real(net_priv *c, struct net_stat *net)
if (sscanf(s,
"%lu %*d %*d %*d %*d %*d %*d %*d %lu",
&net->rx, &net->tx)!= 2) {
DBG("can't read %s statistics\n", c->iface);
DBG("can't read %s statistics %s\n", c->iface, s);
return -1;
}
} else {
DBG("STAT: %s\n", s);
}
return 0;
}

Expand Down