Skip to content

Commit

Permalink
* sunrpc/bindrsvprt.c (bindresvport): Try harder to find a port.
Browse files Browse the repository at this point in the history
	If we tried looking at the usual range without success extend the
	range to even lower ports.q
  • Loading branch information
Ulrich Drepper committed May 23, 2005
1 parent 60839ab commit 3a0cd66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
15 changes: 13 additions & 2 deletions sunrpc/bindrsvprt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)

0 comments on commit 3a0cd66

Please sign in to comment.