diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 1999-11-24 20:02:12 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 1999-11-24 20:02:12 +0000 |
commit | f1215d467b4e6729039195e7478cb53285eacf17 (patch) | |
tree | bb4e3ad3a57b5eddd8394ea748b97114fd5c3172 | |
parent | 2a85a99246e25d5abbe1b496067814fdc7606010 (diff) |
set SO_REUSEADDR and SO_LINGER for forwarded ports.
chip@valinux.com via damien@ibs.com.au
-rw-r--r-- | usr.bin/ssh/channels.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c index a9084d3fe78..c0f3854ce80 100644 --- a/usr.bin/ssh/channels.c +++ b/usr.bin/ssh/channels.c @@ -16,7 +16,7 @@ */ #include "includes.h" -RCSID("$Id: channels.c,v 1.27 1999/11/24 19:53:45 markus Exp $"); +RCSID("$Id: channels.c,v 1.28 1999/11/24 20:02:11 markus Exp $"); #include "ssh.h" #include "packet.h" @@ -879,9 +879,10 @@ void channel_request_local_forwarding(int port, const char *host, int host_port) { - int ch, sock; + int ch, sock, on = 1; struct sockaddr_in sin; extern Options options; + struct linger linger; if (strlen(host) > sizeof(channels[0].path) - 1) packet_disconnect("Forward host name too long."); @@ -900,6 +901,15 @@ channel_request_local_forwarding(int port, const char *host, sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); sin.sin_port = htons(port); + /* + * Set socket options. We would like the socket to disappear as soon + * as it has been closed for whatever reason. + */ + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); + linger.l_onoff = 1; + linger.l_linger = 5; + setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger)); + /* Bind the socket to the address. */ if (bind(sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) packet_disconnect("bind: %.100s", strerror(errno)); |