Re: getting the NIC that my socket connection will go on

From: Nick Patavalis (npat@inaccessnetworks.com)
Date: Thu Sep 18 2003 - 02:44:06 EST


On Wed, Sep 17, 2003 at 05:27:31PM -0500, Lee Chin wrote:
> Hi,
> I have an IP address I want to connect to. How can I tell what NIC Linux will use to make that connection on?

Whichever NIC the routing-table indicates as suitable. In general, and
assuming that you have no "special" routing rules, if you want to
connect (i.e. transmit a packet) to "ip_addr", interfaces for which
the following property holds:

nic_ip_addr & nic_mask == ip_addr & nic_mask

will be considered suitable. Of these, the one which has the most
"restrictive" mask (mask with most "1"s in it) will be used.

/npat

--
After they make styrofoam, what do they ship it in?
-- Stephen Wright
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html