From f1215d467b4e6729039195e7478cb53285eacf17 Mon Sep 17 00:00:00 2001 From: Markus Friedl Date: Wed, 24 Nov 1999 20:02:12 +0000 Subject: set SO_REUSEADDR and SO_LINGER for forwarded ports. chip@valinux.com via damien@ibs.com.au --- usr.bin/ssh/channels.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'usr.bin/ssh') 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)); -- cgit v1.2.3