version 1.225, 2005/10/10 10:23:08 |
version 1.226, 2005/10/11 23:37:37 |
|
|
xfree(remote_ipaddr); |
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. |
* This socket is listening for connections to a forwarded TCP/IP port. |
*/ |
*/ |
|
|
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
{ |
{ |
Channel *c; |
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; |
struct addrinfo hints, *ai, *aitop; |
const char *host, *addr; |
const char *host, *addr; |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
|
|
verbose("socket: %.100s", strerror(errno)); |
verbose("socket: %.100s", strerror(errno)); |
continue; |
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); |
debug("Local forwarding listening on %s port %s.", ntop, strport); |
|
|
/* Bind the socket to the address. */ |
/* Bind the socket to the address. */ |
|
|
freeaddrinfo(aitop); |
freeaddrinfo(aitop); |
return -1; |
return -1; |
} |
} |
|
channel_set_reuseaddr(sock); |
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
debug2("bind port %d: %.100s", port, strerror(errno)); |
debug2("bind port %d: %.100s", port, strerror(errno)); |
close(sock); |
close(sock); |