szabgab has asked for the wisdom of the Perl Monks concerning the following question:

When sending a packet via the network the kernel decides how to send it.

If there is only one network interface in the computer the issue is simple. When there are more than one network interfaces physical or virtual, wired or wireless - does not matter, a decision must be made.

The question how can I know up front - without sending anything - which interface will be used and what is its IP address?

Is there a way I can interrogate the kernel to get back this information?
Is there a Perl module that can do that?

What if I would like to get back this information regarding some other machine far far away?

I could fetch the routing table (from the remote machine as well) and then calculate the routing myself. Well actually I have already implemented this once for Solaris (which is different from UNIX) but that code is currently proprietary at another company and is not heavily tested. Besides it would be so much easier to use something that already written and I don't have to reinvent a wheel.

So is there a tool that can calculate this for me?

Replies are listed 'Best First'.
Re: Packet routing
by atemon (Chaplain) on Jul 26, 2007 at 07:30 UTC

    Hi,

    Packets are routed to different interfaces based on the routing table. To parse the routing table (local or remote) you can try Net::SNMP::HostInfo::IpRouteEntry and Net::SNMP::HostInfo.

    Cheers !

    --VC

    There are three sides to any argument.....
    your side, my side and the right side.