diff -Naur openssh-3.6.1p2/channels.c opensshtest/channels.c
--- openssh-3.6.1p2/channels.c	Mon Mar 10 00:21:17 2003
+++ opensshtest/channels.c	Wed May  7 05:41:59 2003
@@ -2016,12 +2016,13 @@
 
 static int
 channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_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, const char *gateway_addr)
 {
 	Channel *c;
 	int success, sock, on = 1;
 	struct addrinfo hints, *ai, *aitop;
 	const char *host;
+	const char *ga_nodename;
 	char ntop[NI_MAXHOST], strport[NI_MAXSERV];
 
 	success = 0;
@@ -2046,7 +2047,8 @@
 	hints.ai_flags = gateway_ports ? AI_PASSIVE : 0;
 	hints.ai_socktype = SOCK_STREAM;
 	snprintf(strport, sizeof strport, "%d", listen_port);
-	if (getaddrinfo(NULL, strport, &hints, &aitop) != 0)
+
+	if (getaddrinfo(gateway_addr, strport, &hints, &aitop) != 0)
 		packet_disconnect("getaddrinfo: fatal error");
 
 	for (ai = aitop; ai; ai = ai->ai_next) {
@@ -2110,10 +2112,10 @@
 /* protocol local port fwd, used by ssh (and sshd in v1) */
 int
 channel_setup_local_fwd_listener(u_short listen_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, const char *gateway_addr)
 {
 	return channel_setup_fwd_listener(SSH_CHANNEL_PORT_LISTENER,
-	    NULL, listen_port, host_to_connect, port_to_connect, gateway_ports);
+	    NULL, listen_port, host_to_connect, port_to_connect, gateway_ports, gateway_addr);
 }
 
 /* protocol v2 remote port fwd, used by sshd */
@@ -2122,7 +2124,7 @@
     u_short listen_port, int gateway_ports)
 {
 	return channel_setup_fwd_listener(SSH_CHANNEL_RPORT_LISTENER,
-	    listen_address, listen_port, NULL, 0, gateway_ports);
+	    listen_address, listen_port, NULL, 0, gateway_ports,NULL);
 }
 
 /*
@@ -2210,7 +2212,7 @@
 				  port);
 #endif
 	/* Initiate forwarding */
-	channel_setup_local_fwd_listener(port, hostname, host_port, gateway_ports);
+	channel_setup_local_fwd_listener(port, hostname, host_port, gateway_ports, NULL);
 
 	/* Free the argument string. */
 	xfree(hostname);
diff -Naur openssh-3.6.1p2/channels.h opensshtest/channels.h
--- openssh-3.6.1p2/channels.h	Mon Jul 22 15:28:54 2002
+++ opensshtest/channels.h	Wed May  7 05:41:59 2003
@@ -200,7 +200,7 @@
 int	 channel_connect_to(const char *, u_short);
 int	 channel_connect_by_listen_address(u_short);
 void	 channel_request_remote_forwarding(u_short, const char *, u_short);
-int	 channel_setup_local_fwd_listener(u_short, const char *, u_short, int);
+int	 channel_setup_local_fwd_listener(u_short, const char *, u_short, int, const char *);
 int	 channel_setup_remote_fwd_listener(const char *, u_short, int);
 
 /* x11 forwarding */
diff -Naur openssh-3.6.1p2/clientloop.c opensshtest/clientloop.c
--- openssh-3.6.1p2/clientloop.c	Tue Apr  1 11:43:39 2003
+++ opensshtest/clientloop.c	Wed May  7 05:41:59 2003
@@ -517,7 +517,7 @@
 	}
 	if (local) {
 		if (channel_setup_local_fwd_listener(fwd_port, buf,
-		    fwd_host_port, options.gateway_ports) < 0) {
+		    fwd_host_port, options.gateway_ports,NULL) < 0) {
 			log("Port forwarding failed.");
 			goto out;
 		}
diff -Naur openssh-3.6.1p2/readconf.c opensshtest/readconf.c
--- openssh-3.6.1p2/readconf.c	Wed May  7 06:19:58 2003
+++ opensshtest/readconf.c	Wed May  7 06:20:38 2003
@@ -744,6 +744,7 @@
 	options->forward_x11 = -1;
 	options->xauth_location = NULL;
 	options->gateway_ports = -1;
+	options->gateway_addr = NULL;
 	options->use_privileged_port = -1;
 	options->rhosts_authentication = -1;
 	options->rsa_authentication = -1;
diff -Naur openssh-3.6.1p2/readconf.h opensshtest/readconf.h
--- openssh-3.6.1p2/readconf.h	Tue Apr  1 11:43:40 2003
+++ opensshtest/readconf.h	Wed May  7 05:41:59 2003
@@ -32,6 +32,7 @@
 	int     forward_x11;	/* Forward X11 display. */
 	char   *xauth_location;	/* Location for xauth program */
 	int     gateway_ports;	/* Allow remote connects to forwarded ports. */
+	char   *gateway_addr;	/* Allow remote connects to forwarded ports on this interface/IP. */
 	int     use_privileged_port;	/* Don't use privileged port if false. */
 	int     rhosts_authentication;	/* Try rhosts authentication. */
 	int     rhosts_rsa_authentication;	/* Try rhosts with RSA
diff -Naur openssh-3.6.1p2/ssh.c opensshtest/ssh.c
--- openssh-3.6.1p2/ssh.c	Mon Feb 24 00:57:32 2003
+++ opensshtest/ssh.c	Wed May  7 22:24:35 2003
@@ -191,7 +191,8 @@
 	fprintf(stderr, "  -D port     Enable dynamic application-level port forwarding.\n");
 	fprintf(stderr, "  -C          Enable compression.\n");
 	fprintf(stderr, "  -N          Do not execute a shell or command.\n");
-	fprintf(stderr, "  -g          Allow remote hosts to connect to forwarded ports.\n");
+	fprintf(stderr, "  -g          Remote hosts routable on our side can connect to forwarded ports.\n");
+	fprintf(stderr, "  -G local-address   Equal to -g but binds the tunnel to this local interface only.\n");
 	fprintf(stderr, "  -1          Force protocol version 1.\n");
 	fprintf(stderr, "  -2          Force protocol version 2.\n");
 	fprintf(stderr, "  -4          Use IPv4 only.\n");
@@ -275,7 +276,7 @@
 
 again:
 	while ((opt = getopt(ac, av,
-	    "1246ab:c:e:fgi:kl:m:no:p:qstvxACD:F:I:L:NPR:TVX")) != -1) {
+	    "1246ab:c:e:fgi:kl:m:no:p:qstvxACD:F:I:L:G:NPR:TVX")) != -1) {
 		switch (opt) {
 		case '1':
 			options.protocol = SSH_PROTO_1;
@@ -305,6 +306,10 @@
 		case 'g':
 			options.gateway_ports = 1;
 			break;
+		case 'G':
+			options.gateway_ports = 1;
+			options.gateway_addr = xstrdup(optarg);
+			break;
 		case 'P':	/* deprecated */
 			options.use_privileged_port = 0;
 			break;
@@ -809,7 +814,7 @@
 {
 	int success = 0;
 	int i;
-
+	
 	/* Initiate local TCP/IP port forwardings. */
 	for (i = 0; i < options.num_local_forwards; i++) {
 		debug("Connections to local port %d forwarded to remote address %.200s:%d",
@@ -820,7 +825,8 @@
 		    options.local_forwards[i].port,
 		    options.local_forwards[i].host,
 		    options.local_forwards[i].host_port,
-		    options.gateway_ports);
+		    options.gateway_ports,
+		    options.gateway_addr);
 	}
 	if (i > 0 && success == 0)
 		error("Could not request local forwarding.");
