Stef Coene wrote:
How do i get the real physical bandwidth of the device?On Friday 23 May 2003 10:44, Srikanth wrote:Hi, The CBQ config file shud be some thing like this. DEVICE=eth0,10Mbit,1Mbit RATE=50Kbit WEIGHT=5Kbit Shall i hardcode the DEVICE BW as 10/100 Mbit or Shall i use any other tool like ethtool for getting this. ethtool gives Speed: 10Mbps If so, how about, if i use some other Interfaces other than eth0, like ppp0 or some other? C'd anybody can give a suggestion over this?Bandwidth should be the real physical bandwidth of the device.
The below program attached is giving the value 6, on my system.
In some other systems, it's giving 2 (don't know whether Kbps/Mbps).
/*Stef
* Gets the bandwidth of the interface.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <db.h>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
//#include <netdb.h>
#include <linux/in.h>
#include <linux/if.h>
#include "ifstats.h"
extern int errno;
int
IFSGetBandwidth (if_stats_desc_struct * ifsd)
{
//#ifdef HAS_SIOCGIFINDEX
int s, status;
struct ifreq ifr;
struct in_addr ina;
if_ip_addr_union ip;
if (ifsd == NULL)
{
printf("case 1\n");
return (-1);
}
/* Must have a specified interface. */
if (ifsd->interface == NULL)
{
printf("case 2\n");
return (-1);
}
/* Create a UDP socket. */
s = socket (AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
printf("case 3\n");
return (-1);
}
/* Set interface name explicitly from ifsd. */
strncpy (ifr.ifr_name, ifsd->interface, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
/* Get bandwidth of interface and put into interface request
* * structure.
* */
status = ioctl(s, SIOCGIFINDEX, &ifr);
/* Close socket. */
close (s);
/* ioctl() failed? */
if (status < 0)
{
perror("! Ioctl");
printf("case 4\n");
return (-1);
}
ifsd->bandwidth = ifr.ifr_bandwidth;
printf("Hello World\n");
printf("Bandwidth: %i\n", ifsd->bandwidth);
//#endif /* HAS_SIOCGIFINDEX */
return (0);
}
main ()
{
int retVal;
if_stats_desc_struct * ifsd;
ifsd = (if_stats_desc_struct *) malloc(sizeof(if_stats_desc_struct));
if (ifsd == NULL)
perror("! Malloc");
ifsd->interface = (char *) malloc(20);
if (ifsd->interface == NULL)
perror("! Malloc");
strcpy(ifsd->interface, "eth0");
retVal = IFSGetBandwidth (ifsd);
free(ifsd->interface);
free(ifsd);
printf("retVal = %d\n", retVal);
}
regards,
Srikanth.