summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>1996-07-29 05:48:39 +0000
committerderaadt <>1996-07-29 05:48:39 +0000
commite193bab90b075c24942aeac8fd10132868c9ee76 (patch)
tree4f0694e5af46235628b2e45edbcd4a38e0a93eac /src
parentf4c9be3243403d728030bb01603f41e6f5c061bc (diff)
downloadopenbsd-e193bab90b075c24942aeac8fd10132868c9ee76.tar.gz
openbsd-e193bab90b075c24942aeac8fd10132868c9ee76.tar.bz2
openbsd-e193bab90b075c24942aeac8fd10132868c9ee76.zip
rresvport() in terms of bind() & bindresvport()
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/net/rcmd.33
-rw-r--r--src/lib/libc/net/rcmd.c26
2 files changed, 15 insertions, 14 deletions
diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3
index 8452e395db..add4faa314 100644
--- a/src/lib/libc/net/rcmd.3
+++ b/src/lib/libc/net/rcmd.3
@@ -134,6 +134,9 @@ by
134and several other functions. Privileged Internet ports are those 134and several other functions. Privileged Internet ports are those
135in the range 0 to 1023. Only the super-user 135in the range 0 to 1023. Only the super-user
136is allowed to bind an address of this sort to a socket. 136is allowed to bind an address of this sort to a socket.
137.Fn rresvport
138needs to be seeded with a port number; if that port
139is not available it will find another.
137.Pp 140.Pp
138The 141The
139.Fn iruserok 142.Fn iruserok
diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c
index 22a956cfb0..28420d20eb 100644
--- a/src/lib/libc/net/rcmd.c
+++ b/src/lib/libc/net/rcmd.c
@@ -228,21 +228,19 @@ rresvport(alport)
228 s = socket(AF_INET, SOCK_STREAM, 0); 228 s = socket(AF_INET, SOCK_STREAM, 0);
229 if (s < 0) 229 if (s < 0)
230 return (-1); 230 return (-1);
231 for (;;) { 231 sin.sin_port = htons((u_short)*alport);
232 sin.sin_port = htons((u_short)*alport); 232 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
233 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) 233 return (s);
234 return (s); 234 if (errno != EADDRINUSE) {
235 if (errno != EADDRINUSE) { 235 (void)close(s);
236 (void)close(s); 236 return (-1);
237 return (-1);
238 }
239 (*alport)--;
240 if (*alport == IPPORT_RESERVED/2) {
241 (void)close(s);
242 errno = EAGAIN; /* close */
243 return (-1);
244 }
245 } 237 }
238 if (bindresvport(s, &sin) == -1) {
239 (void)close(s);
240 return (-1);
241 }
242 *alport = (int)ntohs(sin.sin_port);
243 return (s);
246} 244}
247 245
248int __check_rhosts_file = 1; 246int __check_rhosts_file = 1;