diff cli-runopts.c @ 578:44f486b72427

- tcpfwd bindaddr support against trunk. needs merging.
author Matt Johnston <matt@ucc.asn.au>
date Sat, 27 Feb 2010 11:51:19 +0000
parents f9b5dc0cba61
children 8c737cd7c1af
line wrap: on
line diff
--- a/cli-runopts.c	Sun Sep 13 15:31:29 2009 +0000
+++ b/cli-runopts.c	Sat Feb 27 11:51:19 2010 +0000
@@ -628,13 +628,15 @@
 }
 
 #ifdef ENABLE_CLI_ANYTCPFWD
-/* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding
+/* Turn a "[listenaddr:]listenport:remoteaddr:remoteport" string into into a forwarding
  * set, and add it to the forwarding list */
 static void addforward(const char* origstr, m_list *fwdlist) {
 
+	char *part1 = NULL, *part2 = NULL, *part3 = NULL, *part4 = NULL;
+	char * listenaddr = NULL;
 	char * listenport = NULL;
+	char * connectaddr = NULL;
 	char * connectport = NULL;
-	char * connectaddr = NULL;
 	struct TCPFwdEntry* newfwd = NULL;
 	char * str = NULL;
 
@@ -644,23 +646,43 @@
 	   is never free()d. */ 
 	str = m_strdup(origstr);
 
-	listenport = str;
+	part1 = str;
 
-	connectaddr = strchr(str, ':');
-	if (connectaddr == NULL) {
-		TRACE(("connectaddr == NULL"))
+	part2 = strchr(str, ':');
+	if (part2 == NULL) {
+		TRACE(("part2 == NULL"))
+		goto fail;
+	}
+	*part2 = '\0';
+	part2++;
+
+	part3 = strchr(part2, ':');
+	if (part3 == NULL) {
+		TRACE(("part3 == NULL"))
 		goto fail;
 	}
-	*connectaddr = '\0';
-	connectaddr++;
+	*part3 = '\0';
+	part3++;
+
+	part4 = strchr(part3, ':');
+	if (part4) {
+		*part4 = '\0';
+		part4++;
+	}
 
-	connectport = strchr(connectaddr, ':');
-	if (connectport == NULL) {
-		TRACE(("connectport == NULL"))
-		goto fail;
+	if (part4) {
+		listenaddr = part1;
+		listenport = part2;
+		connectaddr = part3;
+		connectport = part4;
+	} else {
+		listenaddr = NULL;
+		listenport = part1;
+		connectaddr = part2;
+		connectport = part3;
 	}
-	*connectport = '\0';
-	connectport++;
+
+	}
 
 	newfwd = m_malloc(sizeof(struct TCPFwdEntry));
 
@@ -676,6 +698,7 @@
 		goto fail;
 	}
 
+	newfwd->listenaddr = listenaddr;
 	newfwd->connectaddr = connectaddr;
 
 	if (newfwd->listenport > 65535) {