Web lists-archives.com

Re: Cygwin socket option SO_REUSEADDR operates unlike Linux




On Jan 13 00:36, Mark Geisert wrote:
> This report is based on a series of recent list emails with Subject: lines
> "RPC clnt_create() adress already in use" which date back to last September
> but are unfortunately not chained together...  They contain a discussion
> I've been having with OP Raimund Paulus.
> 
> I believe I've distilled the issue(s) down as far as I can.  A
> self-contained STC is included at the end of this email.
> 
> On the latest 64-bit Cygwin, running the STC shows:
> 
> ~ netstat -an|grep :111
>   TCP    0.0.0.0:111            0.0.0.0:0              LISTENING
>   TCP    [::]:111               [::]:0                 LISTENING
>   UDP    0.0.0.0:111            *:*
>   UDP    [::]:111               *:*
> 
> ~ ./bindtest
> 1st socket is 3
> 1st bind OK
> 1st connect OK
> 2nd socket is 3
> 2nd bind OK
> 2nd connect: Address already in use
> 
> ~ ./bindtest
> 1st socket is 3
> 1st bind OK
> 1st connect: Address already in use
> 
> On Fedora 27, running the same STC shows:
> 
> [mark@lux ~]$ netstat -an|grep :111
> tcp        0      0 0.0.0.0:111         0.0.0.0:*        LISTEN
> tcp6       0      0 :::111              :::*             LISTEN
> udp        0      0 0.0.0.0:111         0.0.0.0:*
> udp6       0      0 :::111              :::*
> [mark@lux ~]$ ./bindtest
> 1st socket is 3
> 1st bind OK
> 1st connect OK
> 2nd socket is 3
> 2nd bind OK
> 2nd connect OK

I can't reproduce this:

$ uname -sr
Linux 4.14.13-300.fc27.x86_64
$ netstat -an|grep :111
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
udp        0      0 0.0.0.0:111             0.0.0.0:*                          
udp6       0      0 :::111                  :::*                               
$ ./bindtest
1st socket is 3
1st bind OK
1st connect OK
2nd socket is 3
2nd bind OK
2nd connect: Cannot assign requested address

I tried this a couple of times even as root, just to be sure, but the
result is invariable "2nd connect: Cannot assign requested address".

The error message is different from Cygwin, but the overall behaviour is
the same for me, and it matches the comment I wrote in cygwin_setsockopt
back in 2009 and 2011.

I'm very puzzled that it works for you.  As I wrote in my comment, a
complete duplicate of a local TCP address is not allowed, regardless of
SO_REUSEADDR.

If I may quote Mr. Network himself, the late W. R. Stevens, "UNIX
Network Programming, Networking APIs: Sockets and XTI", Volume 1, 2nd
Edition.  Section 7.5:

  "With TCP we are never able to start multiple servers that bind the
   same IP address and the same port: a 'complete duplicate binding'.
   That is, we cannot start one server that binds 198.69.10.2 port 80
   and start another that also binds 198.69.10.2 port 80, even if we set
   the SO_REUSEADDR soocket option for the second server."


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: signature.asc
Description: PGP signature