Windows Socket Connection from a Multihomed Computer

ID: Q175396

The information in this article applies to:

SUMMARY

This article describes how a network interface card (NIC) is chosen for an outbound IP datagram or stream of datagrams, and how a local source IP address is chosen for those datagrams on a multihomed computer.

MORE INFORMATION

This article applies specifically to applications using the Windows Sockets interface to the TCP/IP stack.

For additional information about how an outbound NIC is chosen for applications using NetBIOS over TCP/IP (such as file and print sharing), please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q166159
   TITLE     : NetBIOS Connections from Multihomed Computer

When a Windows Sockets application binds to a socket, one of the parameters that is passed in the bind() call is the local (source) IP address that should be used for outbound packets. Most applications have no knowledge of network topology, so they specify IPADDR_ANY instead of a specific IP address in their bind() call. IPADDR_ANY tells the stack that the application is going to let the stack choose the "best" local IP address to use, rather than the application specifying one.

On a single-NIC computer, the choice is easy; it will be the IP address of the one NIC in the computer. However, on a multihomed computer, there is a choice to be made by the stack. The stack cannot make an intelligent choice until it knows the target IP address for a TCP connection or a UDP datagram.

When the application sends a connect() call to a target IP address, or sends a send() call to a UDP datagram, the stack references the target IP address and then examines the IP route table so that it can choose the apparent "best" NIC over which to send the packet. After this NIC has been chosen, the stack reads the source IP address associated with that NIC and uses that IP address as the source IP address for the outbound packets.

If the application specifies a source IP address to use in the bind() call, that IP address will be used as the source IP address for TCP connections or UDP datagrams sourced from that socket. However, the route table is still used to route the outbound IP datagrams, based on the target IP address. This can result in the source IP address not being the one associated with the NIC that is chosen to send the packets.

Additional query words: multi-homed multi homed

Keywords          : kbnetwork win95 ntnetserv ntprotocol nttcp NTSrvWkst 
Version           : WinNT:3.5,3.51,4.0;Windows:95
Platform          : WINDOWS
Issue type        : kbinfo

Last Reviewed: May 20, 1998