I'm trying to hurry, but I keep getting confused
Tue, 12 Jan 1999 08:41:14 -0800 (PST)
On Tue, 12 Jan 1999, Mark S. Miller wrote:
> led me to suspect that a TCP port number might normally be associated with
> a host, rather than an IP-address/host-interface. I just performed a set
> of experiments that seemed to confirm that. While putting my laptop in a
> multiple-IP configuration, I created a socket in one process not specifying
> a bindAddr. From another process, I was able to connect to it using its
> port number paired with any of my laptop's IP address, including localhost.
If my understanding is correct, a TCP port number *is* associated with
an individual network interface on a host. For example, the crit.org
machine has two network interfaces, one for 220.127.116.11 (to which
the name "crit.org" resolves) and one for 18.104.22.168 (to which the
name "discuss.foresight.org" resolves).
There can be separate processes bound to the same port on those two
interfaces. At one time we had one web server running on 22.214.171.124
port 80, and a different server (Crit) running on 126.96.36.199 port 80.
This is achieved by binding to a specific address.
When a binding address is not specified, the socket listens on the given
port number on all interfaces, producing the effect you observed.
If you only need to bind to all interfaces or one interface, then you
should be able to get by without extra threads. However, if you need
to pick and choose which interfaces you want to listen on, it will get
more complicated; i believe there isn't any way to specify a list of
interfaces to listen on.