Hello all ,
How can we allow a server to bind to a port that appears to be held open =y a
client process? The netstat below indicates that port 9521 is not b=ing
listened
to by any server process:
$netstat -an | grep 9521
tcp 0 0 127.0.0.1:9521 =A0 127.0.0.1:9521 =A0 ESTABLISHED
tcp 0 0 10.1.235.31:47776 =A0 10.1.19.219:9521 ESTABL=SHED
Ok this should be in FIN_WAIT or FIN_WAIT2 or something.
If it is connected how will the socket be free?
We are using SO_REUSEADDR in the server code, which on Solaris always all=wed
to re-bind to the port in question.
int on = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(=n)) == -1)
printf("setsockopt SO_REUSEADDR failed: port=%= fd=%d", on, fd);
On Linux there appears to be a caveat with using SO_REUSEADDR in conjunct=on
with INADDR_ANY. This is from the Linux socket man page:
SO_REUSEADDR
Indicates that the rules used in =alidating addresses supplied
in a bind(2) call should allow re=se of local addresses. For
PF_INET sockets this means that a=socket may bind, except when
there is an active listening s=cket bound to the address.
When the listening socket i= bound to INADDR_ANY with a spe-
cific port then it is not possibl= to bind to this port for
any local address. despite the fact that no server can bind the port, no new
client can esta=lish a connection to the port.
Also, the client that is established to the port is sending messages t= what
it believes is its peer.? No errors are returned. The socket has been in this
state for couple of a days
I know this question really really well.?
I have faced this problem several times.
But I still can't answer it. I use
setsockopt( ... SO_REUSEADDR..)?
and?
setsockopt(...SO_REUSEPORT..)