Linux环境编程:获取网卡的实时网速(三)

2014-11-23 17:31:55 · 作者: · 浏览: 160
= 0;


bzero(&ndev,sizeof(ndev));
sprintf(ndev.ifs_name,"eth0");


ndev.ifs_us = 100000;


printf("Get %s Speed");
ret = get_if_speed(&ndev);
if(ret < 0)
printf("\t\t\t[Fail]\n");
else
printf("\t\t\t[OK]\n");
float ispeed ,ospeed;
while(1){
ispeed = ndev.ifs_ispeed * 1.0/(ndev.ifs_us/1000 * 0.001);
ospeed = ndev.ifs_ospeed * 1.0/(ndev.ifs_us/1000 * 0.001);


printf("%s: Up Speed: %f MB/s || Down Speed: %f MB/s \r",
ndev.ifs_name,ispeed/(1024.0*1024.0),ospeed/(1024.0*1024.0));


get_if_speed(&ndev);
}



return 0;
} /* ----- End of main() ----- */


可能你有更好的获取网速的办法,求留言指点!