How should I obtain the ip address of default gateway ? Rather than read entries from /proc , is there any standalone API useable ?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- Backbone.js PushState routes .htaccess only workin
- glDrawElements only draws half a quad
A trick would be to use sockets api to attempt to connect to an unreachable ip. The response of "unreachable destination" would come from your default gateway.
you can use libnl which is a library to communicate with the kernel via NETLINK sockets.
a simple example to get the default route would be (please add error checking and the needed headers)