diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-09-26 22:01:25 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-09-26 22:01:25 +0000 |
commit | 7624221d731444b77bd3f827c209177fd34b2e48 (patch) | |
tree | 3ddc8152a9f9ad7d5d513b72887946251127f090 /usr.bin/ssh/sshconnect.c | |
parent | e83d723c92fc28774de76773456c134c781b3fd7 (diff) |
use rresvport(), for random port allocation
Diffstat (limited to 'usr.bin/ssh/sshconnect.c')
-rw-r--r-- | usr.bin/ssh/sshconnect.c | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/usr.bin/ssh/sshconnect.c b/usr.bin/ssh/sshconnect.c index 1ce4b01047f..2e955aad7c6 100644 --- a/usr.bin/ssh/sshconnect.c +++ b/usr.bin/ssh/sshconnect.c @@ -15,7 +15,7 @@ login (authentication) dialog. */ #include "includes.h" -RCSID("$Id: sshconnect.c,v 1.1 1999/09/26 20:53:38 deraadt Exp $"); +RCSID("$Id: sshconnect.c,v 1.2 1999/09/26 22:01:24 deraadt Exp $"); #include <gmp.h> #include "xmalloc.h" @@ -159,29 +159,11 @@ int ssh_create_socket(uid_t original_real_uid, int privileged) if (privileged) { struct sockaddr_in sin; - int p; - for (p = 1023; p > 512; p--) - { - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) - fatal("socket: %.100s", strerror(errno)); - - /* Initialize the desired sockaddr_in structure. */ - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = htons(p); - - /* Try to bind the socket to the privileged port. */ - if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) >= 0) - break; /* Success. */ - if (errno == EADDRINUSE) - { - close(sock); - continue; - } - fatal("bind: %.100s", strerror(errno)); - } + int p = IPPORT_RESERVED - 1; + + sock = rresvport(&p); + if (sock < 0) + fatal("rresvport: %.100s", strerror(errno)); debug("Allocated local port %d.", p); } else |