From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55060 invoked by alias); 13 Jan 2018 21:39:38 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 55024 invoked by uid 89); 13 Jan 2018 21:39:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=Miss, Hx-languages-length:3332, H*u:6.1, H*UA:6.1 X-HELO: m0.truegem.net Received: from m0.truegem.net (HELO m0.truegem.net) (69.55.228.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 13 Jan 2018 21:39:35 +0000 Received: (from daemon@localhost) by m0.truegem.net (8.12.11/8.12.11) id w0DLdYXY072346 for ; Sat, 13 Jan 2018 13:39:34 -0800 (PST) (envelope-from mark@maxrnd.com) Received: from 76-217-5-154.lightspeed.irvnca.sbcglobal.net(76.217.5.154), claiming to be "[192.168.1.100]" via SMTP by m0.truegem.net, id smtpdXb1Qaa; Sat Jan 13 13:39:28 2018 Subject: Re: Cygwin socket option SO_REUSEADDR operates unlike Linux To: cygwin@cygwin.com References: <20180113135127.GA22225@calimero.vinschen.de> From: Mark Geisert Message-ID: Date: Sat, 13 Jan 2018 21:39:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 In-Reply-To: <20180113135127.GA22225@calimero.vinschen.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2018-01/txt/msg00137.txt.bz2 Corinna Vinschen wrote: > 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." Rats. I'll have to investigate a couple of directions, deeper. It makes sense that connect() returns EADDRINUSE rather than bind() because only connect() knows about all 5 parts of the 5-tuple. Stevens is/was the definitive network software guy. Miss him. Most accounts I've found deal with SO_REUSEADDR on the server side, not the client side, so my intuition is a bit faulty. Thanks for your time, Corinna. Raimund: I'll have to do some more digging when I get back to a keyboard in a week or so. Sorry for the delay on this. There might be some issue inside libtirpc where it botches error returns from the kernel. Or something. Thanks all, ..mark -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple