什么是网络 ioctl 手册页?
我想使用 ioctl SIOCGIFADDR 来确定 Linux 中接口的地址。我找到了一些网络参考资料来解释如何执行此操作,但似乎我的系统上已经有一些这方面的参考资料。是否有描述 SIOCGIFADDR 及其朋友的手册页(或其他内容)? man netdevice
很接近,但它没有相关的 ioctl。
I would like to use the ioctl SIOCGIFADDR to determine the address of an interface in Linux. I found some web references that explain how to do this, but it seems like there should be some reference for this already on my system. Is there a man page (or something else) that describes SIOCGIFADDR and friends? man netdevice
is close, but it doesn't have the ioctl in question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ioctl 似乎已被弃用。更好的方法(尽管更复杂)是使用
netlink
。例如,请参阅这篇文章 如何通过 netlink 列出所有接口(对于ioctl
版本,请参阅 该文章迷你系列的第 2 部分)。还有一些库可以更轻松地与netlink
交互,例如参见 libnl 和 libmnl。另请参阅这个问题。编辑: 这里是关于如何通过 netlink 获取所有接口的 IP 地址的示例。
The
ioctl
s seem to be deprecated. The better way (though way more complicated) is to usenetlink
. See for example this article on how to list all interfaces via netlink (for anioctl
version, see part 2 of that article mini-series). There are also libraries to interface withnetlink
more easily, see for example libnl and libmnl. Also see this SO question.Edit: Here's an example on how to get the IP addresses of all interfaces via netlink.
我在 Ubuntu 系统上找到的最接近的(通过 grep 手册页和头文件)是
man ioctl_list
,它将调用列出为:The struct in question (
ifreq< /code>)在
/usr/include/net/if.h
中声明,并附有解释每个字段含义的简短注释。除了上述之外,我认为网络是您最好的选择。
The closest I've been able to find on my Ubuntu system (by grepping through man pages and header files) is
man ioctl_list
, which lists the call as:The struct in question (
ifreq
) is declared in/usr/include/net/if.h
along with brief comments explaining the meaning of each field.Other than the above, I sense that the Web is your best bet.
ioctl_list(2)
ioctl_list(2)
netintro(4) 有一个最小的摘要。可惜 Linux 上不可用
netintro(4) has a minimal summary. Too bad its not available on linux