diff options
Diffstat (limited to 'channels.c')
-rw-r--r-- | channels.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/channels.c b/channels.c index b0bc77901..175b59e44 100644 --- a/channels.c +++ b/channels.c | |||
@@ -39,7 +39,7 @@ | |||
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include "includes.h" | 41 | #include "includes.h" |
42 | RCSID("$OpenBSD: channels.c,v 1.225 2005/10/10 10:23:08 djm Exp $"); | 42 | RCSID("$OpenBSD: channels.c,v 1.226 2005/10/11 23:37:37 djm Exp $"); |
43 | 43 | ||
44 | #include "ssh.h" | 44 | #include "ssh.h" |
45 | #include "ssh1.h" | 45 | #include "ssh1.h" |
@@ -1230,6 +1230,19 @@ port_open_helper(Channel *c, char *rtype) | |||
1230 | xfree(remote_ipaddr); | 1230 | xfree(remote_ipaddr); |
1231 | } | 1231 | } |
1232 | 1232 | ||
1233 | static void | ||
1234 | channel_set_reuseaddr(int fd) | ||
1235 | { | ||
1236 | int on = 1; | ||
1237 | |||
1238 | /* | ||
1239 | * Set socket options. | ||
1240 | * Allow local port reuse in TIME_WAIT. | ||
1241 | */ | ||
1242 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) | ||
1243 | error("setsockopt SO_REUSEADDR fd %d: %s", fd, strerror(errno)); | ||
1244 | } | ||
1245 | |||
1233 | /* | 1246 | /* |
1234 | * This socket is listening for connections to a forwarded TCP/IP port. | 1247 | * This socket is listening for connections to a forwarded TCP/IP port. |
1235 | */ | 1248 | */ |
@@ -2191,7 +2204,7 @@ channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_por | |||
2191 | const char *host_to_connect, u_short port_to_connect, int gateway_ports) | 2204 | const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
2192 | { | 2205 | { |
2193 | Channel *c; | 2206 | Channel *c; |
2194 | int sock, r, success = 0, on = 1, wildcard = 0, is_client; | 2207 | int sock, r, success = 0, wildcard = 0, is_client; |
2195 | struct addrinfo hints, *ai, *aitop; | 2208 | struct addrinfo hints, *ai, *aitop; |
2196 | const char *host, *addr; | 2209 | const char *host, *addr; |
2197 | char ntop[NI_MAXHOST], strport[NI_MAXSERV]; | 2210 | char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
@@ -2278,13 +2291,8 @@ channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_por | |||
2278 | verbose("socket: %.100s", strerror(errno)); | 2291 | verbose("socket: %.100s", strerror(errno)); |
2279 | continue; | 2292 | continue; |
2280 | } | 2293 | } |
2281 | /* | 2294 | |
2282 | * Set socket options. | 2295 | channel_set_reuseaddr(sock); |
2283 | * Allow local port reuse in TIME_WAIT. | ||
2284 | */ | ||
2285 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, | ||
2286 | sizeof(on)) == -1) | ||
2287 | error("setsockopt SO_REUSEADDR: %s", strerror(errno)); | ||
2288 | 2296 | ||
2289 | debug("Local forwarding listening on %s port %s.", ntop, strport); | 2297 | debug("Local forwarding listening on %s port %s.", ntop, strport); |
2290 | 2298 | ||
@@ -2710,6 +2718,7 @@ x11_create_display_inet(int x11_display_offset, int x11_use_localhost, | |||
2710 | error("setsockopt IPV6_V6ONLY: %.100s", strerror(errno)); | 2718 | error("setsockopt IPV6_V6ONLY: %.100s", strerror(errno)); |
2711 | } | 2719 | } |
2712 | #endif | 2720 | #endif |
2721 | channel_set_reuseaddr(sock); | ||
2713 | if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { | 2722 | if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
2714 | debug2("bind port %d: %.100s", port, strerror(errno)); | 2723 | debug2("bind port %d: %.100s", port, strerror(errno)); |
2715 | close(sock); | 2724 | close(sock); |