Cygwin socket option SO_REUSEADDR operates unlike Linux

Corinna Vinschen corinna-cygwin@cygwin.com
Sat Jan 13 13:51:00 GMT 2018


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20180113/33e4f0dc/attachment.sig>


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /