Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Gateway in C on Linux

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

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.

like image 947
Matt Avatar asked Feb 13 '09 23:02

Matt


1 Answers

I think reading /proc/net/route will be your best bet. Would you consider this a "file"?

The format of /proc/net/route is well-known, and in-memory, so there's no I/O penalty or fear of this changing (i.e. versus reading something from /etc/network/*)

like image 132
slacy Avatar answered Sep 20 '22 15:09

slacy