diff options
author | Ulrich Drepper <drepper@redhat.com> | 2005-05-23 16:40:54 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2005-05-23 16:40:54 +0000 |
commit | 3a0cd663c2abc74052d79747777141fad142c52f (patch) | |
tree | 97d135adb9aa6be91e8d3a9b747f6c2bbd71f199 /sunrpc/bindrsvprt.c | |
parent | 60839ab9520acb7b2018568b41af4ea12320948c (diff) | |
download | glibc-3a0cd663c2abc74052d79747777141fad142c52f.tar.gz |
* 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
Diffstat (limited to 'sunrpc/bindrsvprt.c')
-rw-r--r-- | sunrpc/bindrsvprt.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/sunrpc/bindrsvprt.c b/sunrpc/bindrsvprt.c index 374518716e..671f229aae 100644 --- a/sunrpc/bindrsvprt.c +++ b/sunrpc/bindrsvprt.c @@ -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) |