summaryrefslogtreecommitdiff
path: root/sunrpc/bindrsvprt.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /sunrpc/bindrsvprt.c
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'sunrpc/bindrsvprt.c')
-rw-r--r--sunrpc/bindrsvprt.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/sunrpc/bindrsvprt.c b/sunrpc/bindrsvprt.c
index 023ae1723b..374518716e 100644
--- a/sunrpc/bindrsvprt.c
+++ b/sunrpc/bindrsvprt.c
@@ -43,15 +43,14 @@
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)
{
@@ -69,30 +68,17 @@ bindresvport (int sd, struct sockaddr_in *sin)
{
port = (__getpid () % NPORTS) + STARTPORT;
}
+ res = -1;
+ __set_errno (EADDRINUSE);
- /* Initialize to make gcc happy. */
- int res = -1;
-
- int nports = ENDPORT - startport + 1;
- int endport = ENDPORT;
- again:
- for (i = 0; i < nports; ++i)
+ for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; ++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;
- }
-
- if (i == nports && startport != LOWPORT)
- {
- startport = LOWPORT;
- endport = STARTPORT - 1;
- nports = STARTPORT - LOWPORT;
- port = LOWPORT + port % (STARTPORT - LOWPORT);
- goto again;
}
return res;