|
Lines 182-192
Link Here
|
| 182 |
fprintf(stderr, " -c cipher Select encryption algorithm\n"); |
182 |
fprintf(stderr, " -c cipher Select encryption algorithm\n"); |
| 183 |
fprintf(stderr, " -m macs Specify MAC algorithms for protocol version 2.\n"); |
183 |
fprintf(stderr, " -m macs Specify MAC algorithms for protocol version 2.\n"); |
| 184 |
fprintf(stderr, " -p port Connect to this port. Server must be on the same port.\n"); |
184 |
fprintf(stderr, " -p port Connect to this port. Server must be on the same port.\n"); |
| 185 |
fprintf(stderr, " -L listen-port:host:port Forward local port to remote address\n"); |
185 |
fprintf(stderr, " -L [listen-host]:listen-port:host:port Forward local port to remote address\n"); |
| 186 |
fprintf(stderr, " -R listen-port:host:port Forward remote port to local address\n"); |
186 |
fprintf(stderr, " -R [listen-host]:listen-port:host:port Forward remote port to local address\n"); |
| 187 |
fprintf(stderr, " These cause %s to listen for connections on a port, and\n", __progname); |
187 |
fprintf(stderr, " These cause %s to listen for connections on a port, and\n", __progname); |
| 188 |
fprintf(stderr, " forward them to the other side by connecting to host:port.\n"); |
188 |
fprintf(stderr, " forward them to the other side by connecting to host:port.\n"); |
| 189 |
fprintf(stderr, " -D port Enable dynamic application-level port forwarding.\n"); |
189 |
fprintf(stderr, " -D [listen-host]:port Enable dynamic application-level port forwarding.\n"); |
| 190 |
fprintf(stderr, " -C Enable compression.\n"); |
190 |
fprintf(stderr, " -C Enable compression.\n"); |
| 191 |
fprintf(stderr, " -N Do not execute a shell or command.\n"); |
191 |
fprintf(stderr, " -N Do not execute a shell or command.\n"); |
| 192 |
fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n"); |
192 |
fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n"); |
|
Lines 249-256
Link Here
|
| 249 |
main(int ac, char **av) |
249 |
main(int ac, char **av) |
| 250 |
{ |
250 |
{ |
| 251 |
int i, opt, exit_status, cerr; |
251 |
int i, opt, exit_status, cerr; |
| 252 |
u_short fwd_port, fwd_host_port; |
252 |
u_short fwd_lport, fwd_cport; |
| 253 |
char sfwd_port[6], sfwd_host_port[6]; |
253 |
char *fwdarg[4], *fwd_lhost, *fwd_chost; |
| 254 |
char *p, *cp, buf[256]; |
254 |
char *p, *cp, buf[256]; |
| 255 |
struct stat st; |
255 |
struct stat st; |
| 256 |
struct passwd *pw; |
256 |
struct passwd *pw; |
|
Lines 464-501
Link Here
|
| 464 |
|
464 |
|
| 465 |
case 'L': |
465 |
case 'L': |
| 466 |
case 'R': |
466 |
case 'R': |
| 467 |
if (sscanf(optarg, "%5[0-9]:%255[^:]:%5[0-9]", |
467 |
cp = p = xstrdup(optarg); |
| 468 |
sfwd_port, buf, sfwd_host_port) != 3 && |
468 |
for (i = 0; i < 4; ++i) |
| 469 |
sscanf(optarg, "%5[0-9]/%255[^/]/%5[0-9]", |
469 |
if ( !(fwdarg[i] = hpdelim(&cp)) ) |
| 470 |
sfwd_port, buf, sfwd_host_port) != 3) { |
470 |
break; |
|
|
471 |
switch(i) { |
| 472 |
case 3: |
| 473 |
fwd_lhost = ""; |
| 474 |
fwd_lport = a2port(fwdarg[0]); |
| 475 |
fwd_chost = cleanhostname(fwdarg[1]); |
| 476 |
fwd_cport = a2port(fwdarg[2]); |
| 477 |
break; |
| 478 |
|
| 479 |
case 4: |
| 480 |
fwd_lhost = cleanhostname(fwdarg[0]); |
| 481 |
fwd_lport = a2port(fwdarg[1]); |
| 482 |
fwd_chost = cleanhostname(fwdarg[2]); |
| 483 |
fwd_cport = a2port(fwdarg[3]); |
| 484 |
break; |
| 485 |
|
| 486 |
default: |
| 471 |
fprintf(stderr, |
487 |
fprintf(stderr, |
| 472 |
"Bad forwarding specification '%s'\n", |
488 |
"Bad forwarding specification '%s'\n", |
| 473 |
optarg); |
489 |
optarg); |
| 474 |
usage(); |
490 |
xfree(p); |
|
|
491 |
exit(1); |
| 475 |
/* NOTREACHED */ |
492 |
/* NOTREACHED */ |
| 476 |
} |
493 |
} |
| 477 |
if ((fwd_port = a2port(sfwd_port)) == 0 || |
494 |
if (fwd_lport == 0 || fwd_cport == 0) { |
| 478 |
(fwd_host_port = a2port(sfwd_host_port)) == 0) { |
|
|
| 479 |
fprintf(stderr, |
495 |
fprintf(stderr, |
| 480 |
"Bad forwarding port(s) '%s'\n", optarg); |
496 |
"Bad forwarding port(s) '%s'\n", optarg); |
|
|
497 |
xfree(p); |
| 481 |
exit(1); |
498 |
exit(1); |
| 482 |
} |
499 |
} |
| 483 |
if (opt == 'L') |
500 |
if (opt == 'L') |
| 484 |
add_local_forward(&options, fwd_port, buf, |
501 |
add_local_forward(&options, |
| 485 |
fwd_host_port); |
502 |
fwd_lhost, fwd_lport, |
|
|
503 |
fwd_chost, fwd_cport); |
| 504 |
|
| 486 |
else if (opt == 'R') |
505 |
else if (opt == 'R') |
| 487 |
add_remote_forward(&options, fwd_port, buf, |
506 |
add_remote_forward(&options, |
| 488 |
fwd_host_port); |
507 |
fwd_lhost, fwd_lport, |
|
|
508 |
fwd_chost, fwd_cport); |
| 509 |
xfree(p); |
| 489 |
break; |
510 |
break; |
| 490 |
|
511 |
|
| 491 |
case 'D': |
512 |
case 'D': |
| 492 |
fwd_port = a2port(optarg); |
513 |
cp = p = xstrdup(optarg); |
| 493 |
if (fwd_port == 0) { |
514 |
fwd_lport = 0; |
|
|
515 |
fwd_lhost = hpdelim(&cp); /* may be NULL */ |
| 516 |
if (cp) { |
| 517 |
fwd_lport = a2port(cp); |
| 518 |
fwd_lhost = cleanhostname(fwd_lhost); |
| 519 |
} else { |
| 520 |
fwd_lport = a2port(fwd_lhost); |
| 521 |
fwd_lhost = ""; |
| 522 |
} |
| 523 |
|
| 524 |
if (fwd_lport == 0) { |
| 494 |
fprintf(stderr, "Bad dynamic port '%s'\n", |
525 |
fprintf(stderr, "Bad dynamic port '%s'\n", |
| 495 |
optarg); |
526 |
optarg); |
|
|
527 |
xfree(p); |
| 496 |
exit(1); |
528 |
exit(1); |
| 497 |
} |
529 |
} |
| 498 |
add_local_forward(&options, fwd_port, "socks4", 0); |
530 |
add_local_forward(&options, |
|
|
531 |
fwd_lhost, fwd_lport, "socks4", 0); |
| 532 |
xfree(p); |
| 499 |
break; |
533 |
break; |
| 500 |
|
534 |
|
| 501 |
case 'C': |
535 |
case 'C': |
|
Lines 834-850
Link Here
|
| 834 |
{ |
868 |
{ |
| 835 |
int success = 0; |
869 |
int success = 0; |
| 836 |
int i; |
870 |
int i; |
|
|
871 |
char *listen_host; |
| 837 |
|
872 |
|
| 838 |
/* Initiate local TCP/IP port forwardings. */ |
873 |
/* Initiate local TCP/IP port forwardings. */ |
| 839 |
for (i = 0; i < options.num_local_forwards; i++) { |
874 |
for (i = 0; i < options.num_local_forwards; i++) { |
| 840 |
debug("Connections to local port %d forwarded to remote address %.200s:%d", |
875 |
listen_host = options.local_forwards[i].listen_host; |
| 841 |
options.local_forwards[i].port, |
876 |
if (listen_host[0] == '\0' && !options.gateway_ports) |
| 842 |
options.local_forwards[i].host, |
877 |
listen_host = "localhost"; |
| 843 |
options.local_forwards[i].host_port); |
878 |
debug("Connections to local port %.200s:%d forwarded to remote address %.200s:%d", |
|
|
879 |
listen_host, |
| 880 |
options.local_forwards[i].listen_port, |
| 881 |
options.local_forwards[i].connect_host, |
| 882 |
options.local_forwards[i].connect_port); |
| 844 |
success += channel_setup_local_fwd_listener( |
883 |
success += channel_setup_local_fwd_listener( |
| 845 |
options.local_forwards[i].port, |
884 |
listen_host, |
| 846 |
options.local_forwards[i].host, |
885 |
options.local_forwards[i].listen_port, |
| 847 |
options.local_forwards[i].host_port, |
886 |
options.local_forwards[i].connect_host, |
|
|
887 |
options.local_forwards[i].connect_port, |
| 848 |
options.gateway_ports); |
888 |
options.gateway_ports); |
| 849 |
} |
889 |
} |
| 850 |
if (i > 0 && success == 0) |
890 |
if (i > 0 && success == 0) |
|
Lines 852-865
Link Here
|
| 852 |
|
892 |
|
| 853 |
/* Initiate remote TCP/IP port forwardings. */ |
893 |
/* Initiate remote TCP/IP port forwardings. */ |
| 854 |
for (i = 0; i < options.num_remote_forwards; i++) { |
894 |
for (i = 0; i < options.num_remote_forwards; i++) { |
| 855 |
debug("Connections to remote port %d forwarded to local address %.200s:%d", |
895 |
listen_host = options.remote_forwards[i].listen_host; |
| 856 |
options.remote_forwards[i].port, |
896 |
if (listen_host[0] == '\0' && !options.gateway_ports) |
| 857 |
options.remote_forwards[i].host, |
897 |
listen_host = "localhost"; |
| 858 |
options.remote_forwards[i].host_port); |
898 |
debug("Connections to remote port %.200s:%d forwarded to local address %.200s:%d", |
|
|
899 |
listen_host, |
| 900 |
options.remote_forwards[i].listen_port, |
| 901 |
options.remote_forwards[i].connect_host, |
| 902 |
options.remote_forwards[i].connect_port); |
| 859 |
channel_request_remote_forwarding( |
903 |
channel_request_remote_forwarding( |
| 860 |
options.remote_forwards[i].port, |
904 |
listen_host, |
| 861 |
options.remote_forwards[i].host, |
905 |
options.remote_forwards[i].listen_port, |
| 862 |
options.remote_forwards[i].host_port); |
906 |
options.remote_forwards[i].connect_host, |
|
|
907 |
options.remote_forwards[i].connect_port); |
| 863 |
} |
908 |
} |
| 864 |
} |
909 |
} |
| 865 |
|
910 |
|