Results 1 to 5 of 5
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 ...
- 04-09-2010 #1Just Joined!
- Join Date
- Aug 2006
- Location
- Poland
- Posts
- 17
How to determine network interface that will be used to send 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 RedHat ? 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
- 04-09-2010 #2Just Joined!
- Join Date
- Aug 2006
- Location
- Poland
- Posts
- 17
I would like to share with you what I've already learnt in this topic. So, on Solaris there is a special command that is used to it: "route get <ip address>". As the source code of OpenSolaris is available publicly, I guess it shouldn't be a big problem to check what system calls are used to get the network interface we need.
In turn, on HPUX it seems much more complicated, I have found this information here.
If you have any other ideas, or you know how to do it better please let me know.
Thank you in advance.
Best regards,
Rafal
- 04-10-2010 #3
- 04-12-2010 #4Just Joined!
- Join Date
- Aug 2006
- Location
- Poland
- Posts
- 17
Thanks for response.
Currently I wonder what will happen if the host has two network cards for the same LAN. Generally speaking in this case it is not possible to determine the interface. What do you think ?
PS. I assume that I'm able to configure a kind of dynamic routing where packets can be sent by one of those two interfaces randomly.
- 04-12-2010 #5
You should never have two interfaces connected to the same network unless they are bonded together. If 2 are connected then one of then should be in standby state and only become active when the other is inactive. If not and you are connected to a smart switch it will turn off one of the ports as it will think there is a routing loop.
You can but why would you want to? When you start down the random path it makes it a hassle to troubleshoot issue.PS. I assume that I'm able to configure a kind of dynamic routing where packets can be sent by one of those two interfaces randomly.


Reply With Quote
