Commits

William Giokas committed f874889

Non-static net device name length

When user changes net device name from say, wlan0 to wlp0s0, there is
one more character in the net device name, causing the reading of
/proc/net/dev to fail miserably. Now it is calculated based on the names
length.

Signed-off-by: William Giokas <1007380@gmail.com>

  • Participants
  • Parent commits a2700ac

Comments (0)

Files changed (1)

 
 	while (fgets(buf, bufsize, devfd)) {
 	    if ((netstart = strstr(buf, netdevice)) != NULL) {
-
-		/* With thanks to the conky project at http://conky.sourceforge.net/ */
-		sscanf(netstart + 6, "%llu  %*d     %*d  %*d  %*d  %*d   %*d        %*d       %llu",\
-		       receivedabs, sentabs);
-		fclose(devfd);
-		free(buf);
-		return 0;
+            int netdevlength = sizeof(netdevice) / sizeof(char);
+            /* With thanks to the conky project at http://conky.sourceforge.net/ */
+		    sscanf(netstart + netdevlength, "%llu  %*d     %*d  %*d  %*d  %*d   %*d        %*d       %llu",\
+		           receivedabs, sentabs);
+		    fclose(devfd);
+    		free(buf);
+    		return 0;
 	    }
 	}
 	fclose(devfd);