Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Just 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

  3. #3
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,281
    Quote Originally Posted by foxrafi View Post
    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
    You could simply look at the routing table for this information. If it is not one of the configure networks you are going out the default route.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  4. #4
    Just 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.

  5. #5
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,281
    Quote Originally Posted by foxrafi View Post
    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 ?
    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.

    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.
    You can but why would you want to? When you start down the random path it makes it a hassle to troubleshoot issue.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...