ipv6-support.patch 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
@@ -0,0 +1,56 @@
--- dropbear-0.52.orig/svr-runopts.c	Wed May 13 20:56:03 2009
+++ dropbear-0.52/svr-runopts.c	Wed May 13 22:20:22 2009
@@ -311,27 +311,39 @@
 static void addportandaddress(char* spec) {
 
 	char *myspec = NULL;
+	char *p = NULL;
 
 	if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
 
 		/* We don't free it, it becomes part of the runopt state */
 		myspec = m_strdup(spec);
 
-		/* search for ':', that separates address and port */
-		svr_opts.ports[svr_opts.portcount] = strchr(myspec, ':');
-
-		if (svr_opts.ports[svr_opts.portcount] == NULL) {
-			/* no ':' -> the whole string specifies just a port */
-			svr_opts.ports[svr_opts.portcount] = myspec;
-		} else {
-			/* Split the address/port */
-			svr_opts.ports[svr_opts.portcount][0] = '\0'; 
-			svr_opts.ports[svr_opts.portcount]++;
+		/* [ipv6]:port */
+		if (myspec[0] == '[' && (p = strchr(myspec, ']')) != NULL && *(p+1) == ':') {
+			*p = '\0';
+			p+=2;
+			myspec++;
+			svr_opts.ports[svr_opts.portcount] = p;
 			svr_opts.addresses[svr_opts.portcount] = myspec;
-		}
-
-		if (svr_opts.addresses[svr_opts.portcount] == NULL) {
-			/* no address given -> fill in the default address */
+		} else if ((p = strchr(myspec, '.')) != NULL) {
+			if ((p = strchr(p, ':')) == NULL) {
+				/* ipv4 */
+				svr_opts.ports[svr_opts.portcount] = m_strdup(DROPBEAR_DEFPORT);
+				svr_opts.addresses[svr_opts.portcount] = myspec;
+			} else {
+				/* ipv4:port */
+				*p = '\0';
+				p++;
+				svr_opts.ports[svr_opts.portcount] = p;
+				svr_opts.addresses[svr_opts.portcount] = myspec;
+			}
+		} else if ((p = strchr(myspec, ':')) != NULL && (p = strchr(p, ':')) != NULL) {
+			/* ipv6 */
+			svr_opts.ports[svr_opts.portcount] = m_strdup(DROPBEAR_DEFPORT);
+			svr_opts.addresses[svr_opts.portcount] = myspec;
+		} else {
+			/* port */
+			svr_opts.ports[svr_opts.portcount] = myspec;
 			svr_opts.addresses[svr_opts.portcount] = m_strdup(DROPBEAR_DEFADDRESS);
 		}