How can I set (and replace the existing) default network route from a C program? I'd like to do it without shell commands if possible (this is a low memory embedded system). Also can you set the default route without specifying the gateway IP address? In my application I want to make either ppp0 or eth0 the default route, depending on whether the cable is plugged into eth0 or not.
Thanks, Fred
You can make IOCTL calls to set the default route from a C program.
You could
strace
theroute
command you are wanting to mimic. This gives you the relevant syscalls useful to change routing.You may be interested by the proc(5) interface, e.g. its
/proc/net/route
pseudo-file.See also ip(7).