about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-11-22 04:39:40 +0000
committerUlrich Drepper <drepper@redhat.com>2005-11-22 04:39:40 +0000
commit15a493c3b7ca29256bab871018a51673c26471ba (patch)
tree79a122d7618f62b6d4feb8c9a0e67400c1c3fff5
parent24eb8658395728273ccd98dfd2e93d6b3d493110 (diff)
downloadglibc-15a493c3b7ca29256bab871018a51673c26471ba.tar.gz
glibc-15a493c3b7ca29256bab871018a51673c26471ba.tar.xz
glibc-15a493c3b7ca29256bab871018a51673c26471ba.zip
* sunrpc/bindrsvprt.c (bindresvport): Wrap around to startport
	in the loop if port is bigger than endport, initially set to
	ENDPORT.  When changing startport, set endport and port
	appropriately.
-rw-r--r--ChangeLog7
-rw-r--r--sunrpc/bindrsvprt.c9
2 files changed, 12 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index d12789f50e..05e2d6c75c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-11-21  Jakub Jelinek  <jakub@redhat.com>
+
+	* sunrpc/bindrsvprt.c (bindresvport): Wrap around to startport
+	in the loop if port is bigger than endport, initially set to
+	ENDPORT.  When changing startport, set endport and port
+	appropriately.
+
 2005-11-21  Ulrich Drepper  <drepper@redhat.com>
 
 	* Makefile.in: Remove RCS ID line.
diff --git a/sunrpc/bindrsvprt.c b/sunrpc/bindrsvprt.c
index f58d3b2a8b..023ae1723b 100644
--- a/sunrpc/bindrsvprt.c
+++ b/sunrpc/bindrsvprt.c
@@ -74,14 +74,13 @@ bindresvport (int sd, struct sockaddr_in *sin)
   int res = -1;
 
   int nports = ENDPORT - startport + 1;
+  int endport = ENDPORT;
  again:
   for (i = 0; i < nports; ++i)
     {
       sin->sin_port = htons (port++);
-      if (port > ENDPORT)
-	{
-	  port = startport;
-	}
+      if (port > endport)
+	port = startport;
       res = __bind (sd, sin, sizeof (struct sockaddr_in));
       if (res >= 0 || errno != EADDRINUSE)
 	break;
@@ -90,7 +89,9 @@ bindresvport (int sd, struct sockaddr_in *sin)
   if (i == nports && startport != LOWPORT)
     {
       startport = LOWPORT;
+      endport = STARTPORT - 1;
       nports = STARTPORT - LOWPORT;
+      port = LOWPORT + port % (STARTPORT - LOWPORT);
       goto again;
     }