On Tuesday 01 February 2005 09:37, Greg Freemyer wrote:
On Tue, 1 Feb 2005 09:47:58 +0100 (MET), Verdi March
<cincaipatron@gmx.net> wrote:
Hi,
I've a question on socket programming (I'm a bit rusty on this).
I'm reading an article on NAT, which mentions a case where a client opens two sessions (to two distinct remote end-points), but from the same source ip:port.
How is this possible? I thought every time a client program open a socket to a remote ip:port, the OS will automatically associate the local endpoint with a differrent port number?
Regards, Verdi
I don't know how to do it programatically, but it would not be a violation of tcp/ip.
tcp/ip just requires that one of four values be unique:
source host, source port dest host, dest port.
If any one of those values is unique, then you have a diferent/unique socket.
If they are the same, you have a conflict. I believe some of the socket hi-jacking code out there somehow takes advantage of this conflict. Take a case where there are two users of a system, each establishes a telnet connection to the same host at the same time. In this case, all 4 are the same. When the server, establishes the session, a new pair of ports is set up. So, the actual TCP connection uses a unique port number. It is the initial connection that uses a common port number.
In the case of UDP, it is a bit different since a 2-way connection is not established. The server only needs to wait for data on the socket, and process them when they come in from various hosts. The difference is that TCP establishes a virtual circuit, and guarantees that all data will arrive in tact and in the correct order (even if packets are received out of order). The send(2) or recv(2) functions will return an error value (eg. -1) on error. With UDP, the only real error checking is in the single packet itself. If a packet is lost somewhere the UDP stack will not report it. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9