以编程方式获取链接速度?
我正在编写一个报告本地计算机上网络设备属性的应用程序。我需要 MAC 地址、MTU、链接速度和其他一些信息。我为此使用 udev。我已经弄清楚如何获取 mac 地址和 mtu,但不知道如何获取链接速度。我可以使用 ethtool 从终端获取它,但我需要一种以编程方式获取它的方法。
有谁知道如何使用 udev 或其他库获取链接速度属性?
I am writing an application that reports attributes of network devices on the local machine. I need the mac address, mtu, link speed and a few others. I'm using udev for this. I've already figured out how to get the mac address and mtu, but not how to get the link speed. I can get it with ethtool from the terminal, but I need a way to get it programmatically.
Does anyone know how I can get the link speed attribute with udev or another library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
SIOCETHTOOL
ioctl() 调用。有一个很好的 ioctl/SIOCETHTOOL 介绍 在 LinuxJournal 上调用,下面的代码(这并不是良好的 C 实践的示例!)应该向您展示如何使用它来获得速度。You need to use the
SIOCETHTOOL
ioctl() call. There's a nice introduction to ioctl/SIOCETHTOOL call on LinuxJournal, and the code below (which is not intended to be an example of good C practices!) should show you how to use it to get the speed.您可以使用 sysfs 接口获取每秒比特数的链接速度:
You can get the link speed in bit per second using the
sysfs
interface: