IOKit 头文件assert.h 不见了?

发布于 2024-08-25 17:13:17 字数 452 浏览 5 评论 0原文

我想获取我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2024-09-01 17:13:17

您必须尝试从用户空间执行此操作;如果您为内核编写代码,则不会使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文