can I read/write the routing table in C without using system() command?


http://stackoverflow.com/questions/6358431/can-i-read-write-the-routing-table-in-c-without-using-system-command


You can open a netlink socket and send route update messages. There is an article about how to do this.


-----------------------------------------------------------------------------------------------------------------------------------


You can also run "strace route add ..." to see how the route command does it.

On my system, it uses ioctl with SIOCADDRT. A little searching turns up some sample code.

Oddly, the best documentation I have found is from IBM's AS400 man pages.

If you just want to read the routing table, you can open and read /proc/net/route. (Again, strace shows that this is how the route command does it.) The hex numbers are 32-bit IP addresses in machine-endian form. Try cat /proc/net/route.


posted @ 2016-06-22 08:14  张同光  阅读(89)  评论(0编辑  收藏  举报