Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以使用 getifaddrs() 或其他方式(以编程方式)获取接口的路由网关信息吗?
是的你可以。参见手册页route(4)。
route(4)
您可以使用sysctl()转储路由信息。在 MIB 中,第一个值必须设置为CTL_NET,第二个值必须设置为AF_ROUTE。
sysctl()
CTL_NET
AF_ROUTE
如果可用(因为它是 freebsd),你可以读出/proc/net/route.
/proc/net/route