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

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() ----- */

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/5559c2cd249e14d723739add823d2e93.html