From The Compiler, 6 Years ago, written in Perl.
Embed
  1. --- /usr/bin/mosh       2012-11-12 07:45:00.000000000 +0100
  2. +++ /home/florian/mosh2 2012-11-20 14:38:42.099611414 +0100
  3. @@ -143,51 +143,6 @@
  4.  
  5.  delete $ENV{ 'MOSH_PREDICTION_DISPLAY' };
  6.  
  7. -if ( defined $fake_proxy ) {
  8. -  use Errno qw(EINTR);
  9. -  use IO::Socket::INET;
  10. -  use POSIX qw(_exit);
  11. -
  12. -  my ( $host, $port ) = @ARGV;
  13. -
  14. -  # Resolve hostname
  15. -  my $packed_ip = gethostbyname $host;
  16. -  if ( not defined $packed_ip ) {
  17. -    die "$0: Could not resolve hostname $host\n";
  18. -  }
  19. -  my $ip = inet_ntoa $packed_ip;
  20. -
  21. -  print STDERR "MOSH IP $ip\n";
  22. -
  23. -  # Act like netcat
  24. -  my $sock = IO::Socket::INET->new( PeerAddr => $ip,
  25. -                                   PeerPort => $port,
  26. -                                   Proto => "tcp" )
  27. -    or die "$0: connect to host $ip port $port: $!\n";
  28. -  binmode($sock);
  29. -  binmode(STDIN);
  30. -  binmode(STDOUT);
  31. -
  32. -  sub cat {
  33. -    my ( $from, $to ) = @_;
  34. -    while ( my $n = $from->sysread( my $buf, 4096 ) ) {
  35. -      next if ( $n == -1 && $! == EINTR );
  36. -      $n >= 0 or last;
  37. -      $to->write( $buf ) or last;
  38. -    }
  39. -  }
  40. -
  41. -  defined( my $pid = fork ) or die "$0: fork: $!\n";
  42. -  if ( $pid == 0 ) {
  43. -    cat $sock, \*STDOUT; $sock->shutdown( 0 );
  44. -    _exit 0;
  45. -  }
  46. -  $SIG{ 'HUP' } = 'IGNORE';
  47. -  cat \*STDIN, $sock; $sock->shutdown( 1 );
  48. -  waitpid $pid, 0;
  49. -  exit;
  50. -}
  51. -
  52.  if ( scalar @ARGV < 1 ) {
  53.    die $usage;
  54.  }
  55. @@ -243,20 +198,20 @@
  56.    }
  57.  
  58.    my $quoted_self = shell_quote( $0 );
  59. -  exec "$ssh " . shell_quote( '-S', 'none', '-o', "ProxyCommand=$quoted_self --fake-proxy -- %h %p", '-t', $userhost, '--', "$server " . shell_quote( @server ) );
  60. +  exec "$ssh " . shell_quote( '-S', 'none', '-t', $userhost, '--', "$server " . shell_quote( @server ) );
  61.    die "Cannot exec ssh: $!\n";
  62.  } else { # parent
  63. -  my ( $ip, $port, $key );
  64. +  my ( $port, $key );
  65.    my $bad_udp_port_warning = 0;
  66. +  my $packed_ip = gethostbyname $userhost;
  67. +  if ( not defined $packed_ip ) {
  68. +    die "$0: Could not resolve hostname $userhost\n";
  69. +  }
  70. +  my $ip = inet_ntoa $packed_ip;
  71.    close $pty;
  72.    LINE: while ( <$pty_slave> ) {
  73.      chomp;
  74. -    if ( m{^MOSH IP } ) {
  75. -      if ( defined $ip ) {
  76. -       die "$0 error: detected attempt to redefine MOSH IP.\n";
  77. -      }
  78. -      ( $ip ) = m{^MOSH IP (\S+)\s*$} or die "Bad MOSH IP string: $_\n";
  79. -    } elsif ( m{^MOSH CONNECT } ) {
  80. +    if ( m{^MOSH CONNECT } ) {
  81.        if ( ( $port, $key ) = m{^MOSH CONNECT (\d+?) ([A-Za-z0-9/+]{22})\s*$} ) {
  82.         last LINE;
  83.        } else {
  84. @@ -271,10 +226,6 @@
  85.    }
  86.    waitpid $pid, 0;
  87.  
  88. -  if ( not defined $ip ) {
  89. -      die "$0: Did not find remote IP address (is SSH ProxyCommand disabled?).\n";
  90. -  }
  91. -
  92.    if ( not defined $key or not defined $port ) {
  93.      if ( $bad_udp_port_warning ) {
  94.        die "$0: Server does not support UDP port range option.\n";
  95.