Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Traffic statistics with SIOCGIFDATA: (3 Items)
   
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.
Re: Traffic statistics with SIOCGIFDATA  
I've found the solution by myself:

	struct ifdatareq req;

	sd = socket(AF_INET, SOCK_DGRAM, 0);
	if (sd == -1)
	{
		return 0;
	}

	memset(&req, 0x00, sizeof(req));
	strlcpy(req.ifdr_name, iface, sizeof(req.ifdr_name));
	if (ioctl(sd, SIOCGIFDATA, (struct ifdatareq *)&req) < 0)
	{
		return 0;
	}

	*packetRecv = req.ifdr_data.ifi_ipackets;

 Thanks anyway!!
Re: Traffic statistics with SIOCGIFDATA  
> I've found the solution by myself:
> 
> 	struct ifdatareq req;
> 
> 	sd = socket(AF_INET, SOCK_DGRAM, 0);
> 	if (sd == -1)
> 	{
> 		return 0;
> 	}
> 
> 	memset(&req, 0x00, sizeof(req));
> 	strlcpy(req.ifdr_name, iface, sizeof(req.ifdr_name));
> 	if (ioctl(sd, SIOCGIFDATA, (struct ifdatareq *)&req) < 0)
> 	{
> 		return 0;
> 	}
> 
> 	*packetRecv = req.ifdr_data.ifi_ipackets;
> 
>  Thanks anyway!!

Why the req.ifdr_data.ifi_baudrate = 10 000 000 always? ( I'm verify this on 1 Gigabit Eth & 100 Mb Eth card )