diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-07-29 05:48:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-07-29 05:48:40 +0000 |
commit | afb337c6ff67cd49309c3e414995db57f8be5824 (patch) | |
tree | 69102e6b39b8d4273f26e0050c484558307a3781 /lib/libc/net/rcmd.c | |
parent | 089f0b9d36e1645042d7d82329d7e14ac207491f (diff) |
rresvport() in terms of bind() & bindresvport()
Diffstat (limited to 'lib/libc/net/rcmd.c')
-rw-r--r-- | lib/libc/net/rcmd.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 22a956cfb05..28420d20ebe 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -228,21 +228,19 @@ rresvport(alport) s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) return (-1); - for (;;) { - sin.sin_port = htons((u_short)*alport); - if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) - return (s); - if (errno != EADDRINUSE) { - (void)close(s); - return (-1); - } - (*alport)--; - if (*alport == IPPORT_RESERVED/2) { - (void)close(s); - errno = EAGAIN; /* close */ - return (-1); - } + sin.sin_port = htons((u_short)*alport); + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) + return (s); + if (errno != EADDRINUSE) { + (void)close(s); + return (-1); } + if (bindresvport(s, &sin) == -1) { + (void)close(s); + return (-1); + } + *alport = (int)ntohs(sin.sin_port); + return (s); } int __check_rhosts_file = 1; |