=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/channels.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- src/usr.bin/ssh/channels.c 1999/11/24 19:53:45 1.27 +++ src/usr.bin/ssh/channels.c 1999/11/24 20:02:11 1.28 @@ -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 @@ 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."); @@ -899,6 +900,15 @@ else 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)