]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2005-05-23 Ulrich Drepper <drepper@redhat.com>
authorRoland McGrath <roland@gnu.org>
Mon, 18 Jul 2005 01:43:31 +0000 (01:43 +0000)
committerRoland McGrath <roland@gnu.org>
Mon, 18 Jul 2005 01:43:31 +0000 (01:43 +0000)
[BZ #1086]
* sunrpc/bindrsvprt.c (LOWPORT): Apparently some mountd
implementations are broken and don't accept ports < 512.
[BZ #1086]
* sunrpc/bindrsvprt.c (bindresvport): Try harder to find a port.
If we tried looking at the usual range without success extend the
range to even lower ports.

sunrpc/bindrsvprt.c

index 374518716ef8665f5ff4d4c0f924bbab47d4a976..f58d3b2a8b22bcc3c7f3c406a49515ceb020caf1 100644 (file)
 int
 bindresvport (int sd, struct sockaddr_in *sin)
 {
-  int res;
   static short port;
   struct sockaddr_in myaddr;
   int i;
 
 #define STARTPORT 600
+#define LOWPORT 512
 #define ENDPORT (IPPORT_RESERVED - 1)
 #define NPORTS (ENDPORT - STARTPORT + 1)
+  static short startport = STARTPORT;
 
   if (sin == (struct sockaddr_in *) 0)
     {
@@ -68,17 +69,29 @@ bindresvport (int sd, struct sockaddr_in *sin)
     {
       port = (__getpid () % NPORTS) + STARTPORT;
     }
-  res = -1;
-  __set_errno (EADDRINUSE);
 
-  for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; ++i)
+  /* Initialize to make gcc happy.  */
+  int res = -1;
+
+  int nports = ENDPORT - startport + 1;
+ again:
+  for (i = 0; i < nports; ++i)
     {
       sin->sin_port = htons (port++);
       if (port > ENDPORT)
        {
-         port = STARTPORT;
+         port = startport;
        }
       res = __bind (sd, sin, sizeof (struct sockaddr_in));
+      if (res >= 0 || errno != EADDRINUSE)
+       break;
+    }
+
+  if (i == nports && startport != LOWPORT)
+    {
+      startport = LOWPORT;
+      nports = STARTPORT - LOWPORT;
+      goto again;
     }
 
   return res;