问题描述
我写一个嵌入式平台,需要根据其在给定时间上连接的接口更改设备的默认路由上运行的守护进程。我怎样才能做到这一点编程?我知道我可以使用系统(路线德尔默认和放大器;&放大器;路由添加默认网关嗒嗒);等,但有一个更直接的方法?
I am writing a daemon running on an embedded platform that needs to change the default route of the device according to which interface it is connecting on at a given time. How can I do this programatically? I know I can use system("route del default && route add default gateway blah"); etc but is there a more direct way?
更新:我通过发现了一个补丁,pppd的,允许replacedefaultroute选项解决了我特别的问题。该补丁还包含code以编程方式修改路由表。它包括本Gentoo的bug报告中
UPDATE: I solved my particular problem by discovering a patch to pppd that allows a replacedefaultroute option. The patch also includes code for programmatically modifying the routing table. It is included in this gentoo bug report http://bugs.gentoo.org/227321
推荐答案
查看SIOCADDRT / SIOCDELRT的ioctl(Stevens的UNIX网络编程将是一个很好的参考。)
Check out SIOCADDRT/SIOCDELRT ioctls (Stevens' "Unix Network Programming" would be a good reference.)
这篇关于如何以编程编辑路由表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!