diff options
author | deraadt <> | 1996-07-29 05:48:39 +0000 |
---|---|---|
committer | deraadt <> | 1996-07-29 05:48:39 +0000 |
commit | e193bab90b075c24942aeac8fd10132868c9ee76 (patch) | |
tree | 4f0694e5af46235628b2e45edbcd4a38e0a93eac /src | |
parent | f4c9be3243403d728030bb01603f41e6f5c061bc (diff) | |
download | openbsd-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.3 | 3 | ||||
-rw-r--r-- | src/lib/libc/net/rcmd.c | 26 |
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 | |||
134 | and several other functions. Privileged Internet ports are those | 134 | and several other functions. Privileged Internet ports are those |
135 | in the range 0 to 1023. Only the super-user | 135 | in the range 0 to 1023. Only the super-user |
136 | is allowed to bind an address of this sort to a socket. | 136 | is allowed to bind an address of this sort to a socket. |
137 | .Fn rresvport | ||
138 | needs to be seeded with a port number; if that port | ||
139 | is not available it will find another. | ||
137 | .Pp | 140 | .Pp |
138 | The | 141 | The |
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 | ||
248 | int __check_rhosts_file = 1; | 246 | int __check_rhosts_file = 1; |