From 34f031982fbf9ce6eb23e47f7f0aeede175cd596 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 5 Feb 2018 19:27:55 +0100 Subject: 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 --- winsup/cygwin/net.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'winsup/cygwin/net.cc') diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 8969e7c6f..b6890121a 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++) -- cgit v1.2.3