Linux 上 C 语言中的默认网关 [英] Default Gateway in C on Linux

查看:23
本文介绍了Linux 上 C 语言中的默认网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Linux 上使用 C 找到路由表的默认网关?

How do you find the default gateway of a routing table using C on Linux?

我不想调用 shell 或读取文件.有用于添加和删除路由(SIOCADDRT、SIOCDELRT)的 ioctl,我在参考获取路由(SIOCGRTCONF)时找到了,但我使用的内核版本似乎不支持 SIOCGRTCONF.

I don't want to issue a call to the shell or read a file. There are ioctls for adding and deleteing routes (SIOCADDRT, SIOCDELRT) and I've found on reference to getting routes (SIOCGRTCONF) but it seems that the version of the kernel I'm using doesn't support SIOCGRTCONF.

推荐答案

您可能需要使用 NETLINK_ROUTE 套接字, 的一部分PF_NETLINK 系列的套接字.查看iproute"的ip"程序部分的源代码.具体来说,它的路线"子命令.

You will probably need to use a NETLINK_ROUTE socket, part of the PF_NETLINK family of sockets. Check out the source code of the 'ip' program part of 'iproute'. Specifically, its 'route' subcommand.

这篇关于Linux 上 C 语言中的默认网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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