How to determine network interface that will be used to send a packet for an IP

Hello,
I'm writing to you because I encountered the following problem. My program displayes all network interfaces that are available in the system, but I would like to add a functionality in which a user can enter a destination address IP (ex. the IP address of the Google search engine) and will get information which network interface will be used to send it. As I know it is associated with reading information from routing table in the system. Maybe you know the API (functions/methods) which I could use to do it in HP-UX ? I program in C/C++, but if you know how to do it in other programming languages (Java, Perl, Python) I will be grateful for any information.

Thank you for any help, tips and suggestions.

Best regards,
Foxrafi

---------- Post updated at 12:53 PM ---------- Previous update was at 01:55 AM ----------

Just to share with you what I've already learnt. On Solaris there is a command: "route get <ip address>" which shows the network interface that will be used for network communication with this IP address. Example:
route get 9.168.23.12.
As source code for OpenSolaris is available publicly it shouldn't be difficult to find what system calls are used to it, I think so.

I've also found a short discussion about this topic on the HP-UX forum: here .
It turns out that on HP-UX you're not able to achieve it in a simple way.

If you have any other ideas how solve my problem :), I will appreciate that.

You can always have a look at the /etc/rc.config.d/netconf file to see what/how interfaces are configured...