wmnet: Cope with interface name longer than 6 characters
commitcd4947f139309f758130ea27d673ce7742d6486a
authorCarlos R. Mafra <crmafra@gmail.com>
Sun, 11 Jan 2015 12:20:02 +0000 (11 12:20 +0000)
committerCarlos R. Mafra <crmafra@gmail.com>
Sun, 11 Jan 2015 13:16:40 +0000 (11 13:16 +0000)
tree8308874bd00b0cbdfbbde1d7c6a9ffab9884cb5c
parente3c0e9452b7f3cd5c851456e1c412f52c9607f49
wmnet: Cope with interface name longer than 6 characters

After a recent change in the kernel (their commit 6e094bd) my
wireless interface name is 8 characters long, wlp3s0b1. But
the wmnet code to read the received bytes

totalbytes_in = strtoul(&buffer[7], NULL, 10);

assumed that the interface name in /proc/net/dev would be 6 characters
long (and would start reading at position 7).

In the linux kernel mailing list I reported the regression and none
other than Al Viro replied,

> I am not sure if 'wmnet' could do this better (any suggestions?),

*snort*

well, yes - it's called scanf().  And if one is really, really nervous
about the overhead of <gasp> parsing a bunch of integers (as if fopen/
fgets/fclose alone won't cost enough to make constantly calling that
sucker a bad idea), just use ptr + <something> - 6 instead of
&buffer[<something>] in there.  That thing has just found where the
colon was (and replaced it with NUL), so dealing with "the first field
turned out to be too long and shifted everything past it" isn't hard.

******

I also took the oportunity to remove the unused variables diffpackets_{in,out}
wmnet/drivers.c
wmnet/wmnet.h