【问题标题】:How to get IP addresses of all interfaces on OS X using C如何使用 C 获取 OS X 上所有接口的 IP 地址
【发布时间】:2015-12-15 06:55:49
【问题描述】:

我正在将代码从 linux 移植到 OS X,但出现这些错误:

src/proxy_linux.c:784: error: 'SIOCGIFHWADDR' undeclared (first use in this function)
src/proxy_linux.c:784: error: (Each undeclared identifier is reported only once
src/proxy_linux.c:784: error: for each function it appears in.)
src/proxy_linux.c:788: error: 'struct ifreq' has no member named 'ifr_hwaddr'

我使用 Mac OS X 10.7.5 (11G63) ) 作为开发系统。

SIOCGIFHWADDR 在 OS X 上不受支持,我找不到任何可以列出所有接口的 IP 地址和 MAC 地址的可靠来源。我在苹果开发者网站上找到的唯一一个使用“IOKit”,它也不向后兼容。在这方面的任何帮助将不胜感激

【问题讨论】:

  • 为什么不使用arp 进行mac-ip 检索?
  • @hacks 我猜你在谈论 linux 命令,但我想要一些关于语句/函数调用序列的提示,通过这些我可以检索与 ip addr 相关的信息以及所有 C 中的所有信息
  • 你需要在你的mac上安装arp包。我在我的mac上使用它。安装macport,然后通过它进行arp。

标签: c macos ioctl


【解决方案1】:

如果不涉及 Sandbox 或 App Store,您可以自己解析 ifconfig -a 的输出并提取地址。如果是这样,那么您就很倒霉了,因为出于隐私原因,Apple 不允许这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-26
    • 2020-05-20
    • 2011-01-18
    • 2018-01-26
    • 1970-01-01
    • 2013-07-28
    • 2014-05-26
    • 1970-01-01
    相关资源
    最近更新 更多