Package: vnstat
Version: 1.4-4
Severity: normal
Tags: patch

vnstat collects data from the wrong interface if you have interfaces
with more than one digit in the interface name:

  # vnstat -D -u -i eth1
  arg 1: "-D"
  arg 2: "-u"
  Updating database...
  arg 3: "-i"
  Used interface: eth1
  bzise 4096
  blocks 4085595
  bfree 1858554
  bavail 1651016
  ffree 1974741
  6604064 free space left
  Database loaded for interface "eth1"...

   eth16:       0       0    0    0    0     0          0         0        0    
   0    0    0    0     0       0          0


  btime 1225467954

  rx: 0 - 0 = 0
  tx: 0 - 0 = 0
  Database saved...

In this case vnstat tries to collect data from eth16 instead of eth1.

The following patch fixes the problem for me:


diff -ur vnstat-1.4.orig/src/proc.c vnstat-1.4/src/proc.c
--- vnstat-1.4.orig/src/proc.c  2004-03-26 14:22:42.000000000 +0100
+++ vnstat-1.4/src/proc.c       2009-01-21 21:37:07.000000000 +0100
@@ -5,7 +5,7 @@
 void readproc(char iface[32])
 {
        FILE *fp;
-       char temp[64], inface[32];
+       char temp[64], inface[32], *p;
        int check;
        
        if ((fp=fopen("/proc/net/dev","r"))==NULL) {
@@ -22,7 +22,9 @@
        check=0;
        while (fgets(procline,512,fp)!=NULL) {
                sscanf(procline,"%s",temp);
-               if (strncmp(inface,temp,strlen(inface))==0) {
+               if ((p = strchr(temp, ':')) != NULL)
+                       *p = '\0';
+               if (strcmp(inface, temp) == 0) {
                        if (debug)
                                printf("\n%s\n",procline);
                        check=1;


As 'apt-get source' seems not to honor apt preferences I started with
sources from the wrong version, so you can get the patch for vnstat 1.6
too ;-)


diff -ur vnstat-1.6.orig/src/ifinfo.c vnstat-1.6/src/ifinfo.c
--- vnstat-1.6.orig/src/ifinfo.c        2008-01-01 17:13:00.000000000 +0100
+++ vnstat-1.6/src/ifinfo.c     2009-01-21 20:58:40.000000000 +0100
@@ -32,7 +32,7 @@
 int readproc(char iface[32])
 {
        FILE *fp;
-       char temp[4][64], procline[512], *proclineptr;
+       char temp[4][64], procline[512], *proclineptr, *p;
        int check;
        
        if ((fp=fopen("/proc/net/dev", "r"))==NULL) {
@@ -44,7 +44,9 @@
        check = 0;
        while (fgets(procline, 512, fp)!=NULL) {
                sscanf(procline, "%s", temp[0]);
-               if (strncmp(iface, temp[0], strlen(iface))==0) {
+               if ((p = strchr(temp[0], ':')) != NULL)
+                       *p = '\0';
+               if (strcmp(iface, temp[0]) == 0) {
                        if (debug)
                                printf("\n%s\n", procline);
                        check = 1;


BTW proc.c seems to be obsolete in version 1.6.

Regards

Uwe


-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (850, 'stable'), (750, 'testing'), (650, 'unstable'), (1, 
'experimental')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-6-k7
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages vnstat depends on:
ii  libc6                  2.3.6.ds1-13etch8 GNU C Library: Shared libraries

vnstat recommends no packages.

-- no debconf information



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to