comparison cli-runopts.c @ 577:69e98c45db7c

- Progress for allowing specifying a listenaddr for tcp forwards
author Matt Johnston <matt@ucc.asn.au>
date Wed, 24 Feb 2010 16:13:15 +0000
parents a3748e54273c
children 8c737cd7c1af
comparison
equal deleted inserted replaced
518:ce104c8b0be1 577:69e98c45db7c
562 562
563 cli_opts.own_user = m_strdup(pw->pw_name); 563 cli_opts.own_user = m_strdup(pw->pw_name);
564 } 564 }
565 565
566 #ifdef ENABLE_CLI_ANYTCPFWD 566 #ifdef ENABLE_CLI_ANYTCPFWD
567 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding 567 /* Turn a "[listenaddr:]listenport:remoteaddr:remoteport" string into into a forwarding
568 * set, and add it to the forwarding list */ 568 * set, and add it to the forwarding list */
569 static void addforward(const char* origstr, struct TCPFwdList** fwdlist) { 569 static void addforward(const char* origstr, struct TCPFwdList** fwdlist) {
570 570
571 char *part1 = NULL, *part2 = NULL, *part3 = NULL, *part4 = NULL;
572 char * listenaddr = NULL;
571 char * listenport = NULL; 573 char * listenport = NULL;
574 char * connectaddr = NULL;
572 char * connectport = NULL; 575 char * connectport = NULL;
573 char * connectaddr = NULL;
574 struct TCPFwdList* newfwd = NULL; 576 struct TCPFwdList* newfwd = NULL;
575 char * str = NULL; 577 char * str = NULL;
576 578
577 TRACE(("enter addforward")) 579 TRACE(("enter addforward"))
578 580
579 /* We need to split the original argument up. This var 581 /* We need to split the original argument up. This var
580 is never free()d. */ 582 is never free()d. */
581 str = m_strdup(origstr); 583 str = m_strdup(origstr);
582 584
583 listenport = str; 585 part1 = str;
584 586
585 connectaddr = strchr(str, ':'); 587 part2 = strchr(str, ':');
586 if (connectaddr == NULL) { 588 if (part2 == NULL) {
587 TRACE(("connectaddr == NULL")) 589 TRACE(("part2 == NULL"))
588 goto fail; 590 goto fail;
589 } 591 }
590 *connectaddr = '\0'; 592 *part2 = '\0';
591 connectaddr++; 593 part2++;
592 594
593 connectport = strchr(connectaddr, ':'); 595 part3 = strchr(part2, ':');
594 if (connectport == NULL) { 596 if (part3 == NULL) {
595 TRACE(("connectport == NULL")) 597 TRACE(("part3 == NULL"))
596 goto fail; 598 goto fail;
597 } 599 }
598 *connectport = '\0'; 600 *part3 = '\0';
599 connectport++; 601 part3++;
602
603 part4 = strchr(part3, ':');
604 if (part4) {
605 *part4 = '\0';
606 part4++;
607 }
608
609 if (part4) {
610 listenaddr = part1;
611 listenport = part2;
612 connectaddr = part3;
613 connectport = part4;
614 } else {
615 listenaddr = NULL;
616 listenport = part1;
617 connectaddr = part2;
618 connectport = part3;
619 }
600 620
601 newfwd = (struct TCPFwdList*)m_malloc(sizeof(struct TCPFwdList)); 621 newfwd = (struct TCPFwdList*)m_malloc(sizeof(struct TCPFwdList));
602 622
603 /* Now we check the ports - note that the port ints are unsigned, 623 /* Now we check the ports - note that the port ints are unsigned,
604 * the check later only checks for >= MAX_PORT */ 624 * the check later only checks for >= MAX_PORT */
610 if (m_str_to_uint(connectport, &newfwd->connectport) == DROPBEAR_FAILURE) { 630 if (m_str_to_uint(connectport, &newfwd->connectport) == DROPBEAR_FAILURE) {
611 TRACE(("bad connectport strtoul")) 631 TRACE(("bad connectport strtoul"))
612 goto fail; 632 goto fail;
613 } 633 }
614 634
635 newfwd->listenaddr = listenaddr;
615 newfwd->connectaddr = connectaddr; 636 newfwd->connectaddr = connectaddr;
616 637
617 if (newfwd->listenport > 65535) { 638 if (newfwd->listenport > 65535) {
618 TRACE(("listenport > 65535")) 639 TRACE(("listenport > 65535"))
619 goto badport; 640 goto badport;