1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
Interface names can be more than 7 chars long.
Patch by Aleksey Fedoseev.
--- vnstat-1.4/src/proc.c
+++ vnstat-1.4/src/proc.c
@@ -64,6 +64,7 @@
void parseproc(int newdb)
{
char temp[64];
+ char* colon_pos;
uint64_t rx, tx, rxchange=0, txchange=0, btime; /* rxchange = rx change in MB */
uint64_t krxchange=0, ktxchange=0; /* krxchange = rx change in kB */
time_t current;
@@ -86,12 +87,22 @@
current=time(NULL);
- /* get rx from procline, easy since it's always procline+7 */
+ /* get rx position, then get it from procline */
+
+ colon_pos = strchr(procline, ':');
+ if (colon_pos == NULL) {
+ if (debug) {
+ printf("Bad /proc/net/dev string");
+ }
+ return;
+ }
+
+ colon_pos++;
#ifdef BLIMIT
- rx=strtoull(procline+7, (char **)NULL, 0);
+ rx=strtoull(colon_pos, (char **)NULL, 0);
#else
- rx=strtoul(procline+7, (char **)NULL, 0);
+ rx=strtoul(colon_pos, (char **)NULL, 0);
#endif
if (newdb!=1) {
@@ -116,7 +127,7 @@
/* get tx from procline, ugly hack */
- sscanf(procline+7,"%s %s %s %s %s %s %s %s %s",temp,temp,temp,temp,temp,temp,temp,temp,temp);
+ sscanf(colon_pos, "%s %s %s %s %s %s %s %s %s",temp,temp,temp,temp,temp,temp,temp,temp,temp);
#ifdef BLIMIT
tx=strtoull(temp, (char **)NULL, 0);
|