IOKit 头文件assert.h 不见了?
我想获取我的 mac 以太网卡的硬件地址。在我看到的所有示例中都包含 IOKit/assert.h 。我的系统上似乎不存在。 GCC 抛出一个错误,表示他不知道 IOEthernetAddress 类型。 我的任务需要assert.h 吗?如果有人能给我一个工作样本,那就太好了。 [编辑]这是我的代码,认为这将有助于理解问题:
#include <IOKit/assert.h>
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>
int main(){
IOEthernetAddress addr;
getHardwareAddress(&addr);
printf("%x", addr);
return 0;
}
I want to get the hardware address of my mac's ethernet card. In all samples I saw in include on IOKit/assert.h . Which doesn't seem to exist on my system. GCC throws an error saying he doesn't know the type IOEthernetAddress.
Is assert.h necessary for my task? It would be great if someone coud give me a working sample.
[edit] here's my code, think this will help understanding the problem:
#include <IOKit/assert.h>
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>
int main(){
IOEthernetAddress addr;
getHardwareAddress(&addr);
printf("%x", addr);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须尝试从用户空间执行此操作;如果您为内核编写代码,则不会使用 main() 。然而,这些是内核包含文件。从用户空间执行此操作的一种方法是查看 I/O 注册表,并找到您感兴趣的硬件的 IOMACAddress。要开始使用此功能,请查看 I/O 注册表资源管理器。
另一种方法是使用 ioctl 和 SIOCSIFLLADDR 来获取链接级地址。
You must be trying to do this from userspace; you wouldn't be using main() if you were writing for the kernel. however, these are kernel include files. One way to do this from userspace is to look at the I/O registry, and find the IOMACAddress for the piece of hardware that interests you. To get started with this, take a look at I/O Registry Explorer.
Another way is to use ioctl with SIOCSIFLLADDR, to get the link level address.