summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/channels.c
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2005-10-11 23:37:38 +0000
committerDamien Miller <djm@cvs.openbsd.org>2005-10-11 23:37:38 +0000
commit4b89bd71fc2e042d7c45156b2deb5724a3f5a218 (patch)
treeb7d8872892b4801fdd856c45d3152f2284eda3fb /usr.bin/ssh/channels.c
parent002b6858ccceebdf23055a01e322389b76eb1703 (diff)
bz #1076 set SO_REUSEADDR on X11 forwarding listner sockets, preventing
bind() failure when a previous connection's listeners are in TIME_WAIT, reported by plattner AT inf.ethz.ch; ok dtucker@
Diffstat (limited to 'usr.bin/ssh/channels.c')
-rw-r--r--usr.bin/ssh/channels.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c
index 2e40907d9e3..e0608f97be3 100644
--- a/usr.bin/ssh/channels.c
+++ b/usr.bin/ssh/channels.c
@@ -39,7 +39,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: channels.c,v 1.225 2005/10/10 10:23:08 djm Exp $");
+RCSID("$OpenBSD: channels.c,v 1.226 2005/10/11 23:37:37 djm Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -1229,6 +1229,19 @@ port_open_helper(Channel *c, char *rtype)
xfree(remote_ipaddr);
}
+static void
+channel_set_reuseaddr(int fd)
+{
+ int on = 1;
+
+ /*
+ * Set socket options.
+ * Allow local port reuse in TIME_WAIT.
+ */
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
+ error("setsockopt SO_REUSEADDR fd %d: %s", fd, strerror(errno));
+}
+
/*
* This socket is listening for connections to a forwarded TCP/IP port.
*/
@@ -2185,7 +2198,7 @@ channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_por
const char *host_to_connect, u_short port_to_connect, int gateway_ports)
{
Channel *c;
- int sock, r, success = 0, on = 1, wildcard = 0, is_client;
+ int sock, r, success = 0, wildcard = 0, is_client;
struct addrinfo hints, *ai, *aitop;
const char *host, *addr;
char ntop[NI_MAXHOST], strport[NI_MAXSERV];
@@ -2272,13 +2285,8 @@ channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_por
verbose("socket: %.100s", strerror(errno));
continue;
}
- /*
- * Set socket options.
- * Allow local port reuse in TIME_WAIT.
- */
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on,
- sizeof(on)) == -1)
- error("setsockopt SO_REUSEADDR: %s", strerror(errno));
+
+ channel_set_reuseaddr(sock);
debug("Local forwarding listening on %s port %s.", ntop, strport);
@@ -2685,6 +2693,7 @@ x11_create_display_inet(int x11_display_offset, int x11_use_localhost,
freeaddrinfo(aitop);
return -1;
}
+ channel_set_reuseaddr(sock);
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
debug2("bind port %d: %.100s", port, strerror(errno));
close(sock);