Alejandro Mingo
|
Traffic statistics with SIOCGIFDATA
|
Alejandro Mingo
01/14/2011 5:20 AM
post82287
|
Traffic statistics with SIOCGIFDATA
Hi all,
I'm trying to get the traffic statistics with the SIOCGIFDATA ioctl as follows:
struct ifreq ifr;
static struct if_data data;
int sd;
if (argc != 2)
{
printf("sintaxis: <iface>");
exit(EXIT_FAILURE);
}
sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd == -1)
{
printf("socket error\n");
exit(EXIT_FAILURE);
}
memset(&ifr, 0x00, sizeof(ifr));
strlcpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name));
ifr.ifr_data = (caddr_t) &data;
if (ioctl(sd, SIOCGIFDATA, &ifr) < 0)
{
printf("ioctl error\n");
exit(EXIT_FAILURE);
}
printf("Bytes received: %u\n", (unsigned int)(data.ifi_ibytes));
I am working with the 6.5.0 release with an io-pkg driver (speedo). I always get 0 for all the struct fields. Is this
the correct way of doing this with io-pkg drivers? I guess no... But how could I do it?
Thanks in advance!
Alex.
|
|
|