]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* sunrpc/bindrsvprt.c (bindresvport): Try harder to find a port.
authorUlrich Drepper <drepper@redhat.com>
Mon, 23 May 2005 16:40:54 +0000 (16:40 +0000)
committerUlrich Drepper <drepper@redhat.com>
Mon, 23 May 2005 16:40:54 +0000 (16:40 +0000)
If we tried looking at the usual range without success extend the
range to even lower ports.q

ChangeLog
sunrpc/bindrsvprt.c

index 5197818f0c515fdd7550f2f4d021bcd2c1602695..e8ffccf8abfd6278a06e9b69b8476820c9c92f6d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2005-05-23  Ulrich Drepper  <drepper@redhat.com>
 
+       * 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.q
+
        * sysdeps/unix/clock_gettime.c (clock_gettime): Revert last patch.
 
 2005-05-22  Andreas Schwab  <schwab@suse.de>
index 374518716ef8665f5ff4d4c0f924bbab47d4a976..671f229aae7a1a66891913a95927f69905891d35 100644 (file)
@@ -49,8 +49,10 @@ bindresvport (int sd, struct sockaddr_in *sin)
   int i;
 
 #define STARTPORT 600
+#define LOWPORT 200
 #define ENDPORT (IPPORT_RESERVED - 1)
 #define NPORTS (ENDPORT - STARTPORT + 1)
+  static short startport = STARTPORT;
 
   if (sin == (struct sockaddr_in *) 0)
     {
@@ -71,16 +73,25 @@ bindresvport (int sd, struct sockaddr_in *sin)
   res = -1;
   __set_errno (EADDRINUSE);
 
-  for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; ++i)
+  int nports = ENDPORT - startport + 1;
+ again:
+  for (i = 0; i < nports && res < 0 && errno == EADDRINUSE; ++i)
     {
       sin->sin_port = htons (port++);
       if (port > ENDPORT)
        {
-         port = STARTPORT;
+         port = startport;
        }
       res = __bind (sd, sin, sizeof (struct sockaddr_in));
     }
 
+  if (i == nports && startport != LOWPORT)
+    {
+      startport = LOWPORT;
+      nports = STARTPORT - LOWPORT;
+      goto again;
+    }
+
   return res;
 }
 libc_hidden_def (bindresvport)