Ker*_*nya 4 linux networking c++ ethernet mac-address
我需要读取网络适配器的永久(烧入)MAC 地址。由于MAC地址很容易被欺骗,我需要读取写在EEPROM上的真实地址。我需要在 Linux 上使用 C++ 来完成它。
我尝试使用ethtool,它非常好并且工作正常。但是,在某些系统上,它无法按预期工作。
ethtool -P eth0
Run Code Online (Sandbox Code Playgroud)
返回这个:
Permanent address: 00:00:00:00:00:00
Run Code Online (Sandbox Code Playgroud)
和
ethtool -e eth0
Run Code Online (Sandbox Code Playgroud)
返回这个:
Cannot get EEPROM data: Operation not supported
Run Code Online (Sandbox Code Playgroud)
网络适配器具有以下信息:
Linux内核版本为:2.6.32.13
问题是:我可以通过任何更新(驱动程序、内核等)来解决这个问题吗?
此外,我使用ioctl
C++ 中的函数进行了相同的 ethtool 调用。有没有办法在代码中解决这个问题?或者有没有其他方法可以从 EEPROM 中获取永久 MAC 地址?
如果您信任的本地机器不被欺骗,都ifconfig
和ip addr
会给你硬件的MAC地址。
如果您不信任本地机器,则 ethtool、ifconfig 和 ip 都不会为您提供所需的信息。因为 MAC 欺骗有非常合理的原因(例如,以太网卡上的热故障)所有驱动程序只报告当前的“虚拟”MAC 地址,因为如果您需要欺骗地址,它对某些工具来说效果不佳上报固件地址,其他人上报软地址。ioctl 不能也不应该给你硬地址。
要获得硬地址需要直接读取设备寄存器,因此完全特定于设备。
A quick look through the ucc_geth.c driver seems to show that MAC address reassignment is supported by the chip itself (which makes sense as it needs to be able to pluck packets sent to its soft address off the ether). This means that you need to be very deliberate to ensure you are getting the hard address for which the driver liberally says:
/* For more details see the hardware spec. */
Run Code Online (Sandbox Code Playgroud)