This is the mail archive of the
cygwin-cvs@cygwin.com
mailing list for the Cygwin project.
[newlib-cygwin] Cygwin: bindresvport_sa: Ignore incoming port number
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: cygwin-cvs at sourceware dot org
- Date: 5 Feb 2018 20:07:10 -0000
- Subject: [newlib-cygwin] Cygwin: bindresvport_sa: Ignore incoming port number
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=34f031982fbf9ce6eb23e47f7f0aeede175cd596
commit 34f031982fbf9ce6eb23e47f7f0aeede175cd596
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Mon Feb 5 19:27:55 2018 +0100
Cygwin: bindresvport_sa: Ignore incoming port number
Ignore port number just like glibc, otherwise suffer EADDRINUSE
in subsequent connect calls.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/net.cc | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 8969e7c..b689012 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -2467,7 +2467,6 @@ cygwin_bindresvport_sa (int fd, struct sockaddr *sa)
struct sockaddr_storage sst;
struct sockaddr_in *sin = NULL;
struct sockaddr_in6 *sin6 = NULL;
- in_port_t port;
socklen_t salen;
int ret = -1;
@@ -2489,27 +2488,20 @@ cygwin_bindresvport_sa (int fd, struct sockaddr *sa)
case AF_INET:
salen = sizeof (struct sockaddr_in);
sin = (struct sockaddr_in *) sa;
- port = sin->sin_port;
break;
case AF_INET6:
salen = sizeof (struct sockaddr_in6);
sin6 = (struct sockaddr_in6 *) sa;
- port = sin6->sin6_port;
break;
default:
set_errno (EPFNOSUPPORT);
__leave;
}
- /* If a non-zero port number is given, try this first. If that succeeds,
- or if the error message is serious, return. */
- if (port)
- {
- ret = fh->bind (sa, salen);
- if (!ret || (get_errno () != EADDRINUSE && get_errno () != EINVAL))
- __leave;
- }
-
+ /* Originally we tried to use the incoming port number first here,
+ but that may lead to EADDRINUSE scenarios when calling bindresvport
+ on the client side. So we ignore any port value that the caller
+ supplies, just like glibc. */
LONG myport;
for (int i = 0; i < NUM_PORTS; i++)