ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
i'm trying to write a program that detects the speed of the network card connection of the host where it is running.
For example 10Mbps, 100Mbps or else.
Somebody can help me?
I can measure the current traffic by reading the file /proc/net/dev.
What i want to know is the Total Bandwidth ( or also the free Bandwidth ). i haven't found it anywhere...
Thanks!
Then it's rather tricky. For Ethernet, for instance, you can read it from driver settings. But you will never reach the theoretical maximum. For wireless interfaces it's even worse. There's theory, but you (usually) have no guarantee. For wireless the only way is to measure.
so you say that the best way to get an indication is to measure the traffic.ok!
Anyway i'm interested on the theoretical Bandwidth, i don't mind if it is not reacheable... is there any API that can help me?
you also said to give a look at the driver settings... can you give me some advice?
THANKS!
You should be able to get the stats using the netlink socket, while getting all possible interface info. libnl, which makes dealing with netlink easier, does not support it, however, so you would need to do that manually. If you have never tried it, it may be quite complicated, mostly because lack of full documentation so you need to browse the kernel code to see all you need.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.