How to check if Kernel has a route to a particular IP address
Hi,
I'm working on a userspace application that needs to find if the kernel has a route configured for a particular destination address, and what port it would be routed from. I'm hoping there is a simple kernel call that will do this for me, but haven't been able to find it yet :-)
I don't want to actually send a packet to do this, just query the kernel if where it *would* send the packet if I did.
The only method I've come up with is to get the kernel routing table through rtnetlink then check each entry to see if it matches my destination address. I guess this will work (after one or two tries to get the logic right ;-) ) but I'd rather do a single call if there is one.
Thanks in advance
|