在 FreeBSD 上使用 IP 枚举所有网络接口 [英] Enumerate all network interfaces with IPs on FreeBSD

查看:19
本文介绍了在 FreeBSD 上使用 IP 枚举所有网络接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要列出机器上的所有网络接口及其 IP、IPv4 和 IPv6.

My application needs to list all network interafaces on a machine and their IPs, IPv4 and IPv6.

我可以使用 ioctl(SIOCGIFCONF) 获取所有带有 IPv4 IP 的接口,但我也需要 IPv6 IP.

I can get all interfaces with IPv4 IPs using ioctl(SIOCGIFCONF), but I need the IPv6 IPs, too.

在 Linux 上,这些可以从/proc/net/if_inet6 获得,但我在 FreeBSD 上从哪里获得?

On Linux, those can get gotten from /proc/net/if_inet6, but where would I get them on FreeBSD ?

推荐答案

getifaddrs(3) 提供了可移植的方式来获取网络地址和接口名称.

getifaddrs(3) provides portable way to get network addresses and interface names.

这篇关于在 FreeBSD 上使用 IP 枚举所有网络接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆