Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have code written in C. I want to get using C code information that is stored in routing table. Is it possible?

like image 512
cateof Avatar asked Jun 15 '11 13:06

cateof


2 Answers

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.

like image 143
Nemo Avatar answered Oct 20 '22 13:10

Nemo


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

like image 30
Keith Avatar answered Oct 20 '22 15:10

Keith