scripts/mosh: Let IO::Socket resolve the hostname
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
+9
-13
@@ -34,8 +34,8 @@ my $MOSH_VERSION = '1.2.4a';
|
|||||||
|
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use Socket;
|
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
use IO::Socket;
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
|
|
||||||
@@ -168,25 +168,21 @@ if ( not defined $bind_ip or $bind_ip =~ m{^ssh$}i ) {
|
|||||||
|
|
||||||
if ( defined $fake_proxy ) {
|
if ( defined $fake_proxy ) {
|
||||||
use Errno qw(EINTR);
|
use Errno qw(EINTR);
|
||||||
use IO::Socket::INET;
|
|
||||||
use POSIX qw(_exit);
|
use POSIX qw(_exit);
|
||||||
|
|
||||||
my ( $host, $port ) = @ARGV;
|
my ( $host, $port ) = @ARGV;
|
||||||
|
|
||||||
# Resolve hostname
|
# Resolve hostname and connect
|
||||||
my $packed_ip = gethostbyname $host;
|
my $sock = IO::Socket->new( Domain => AF_INET,
|
||||||
if ( not defined $packed_ip ) {
|
Family => AF_INET,
|
||||||
die "$0: Could not resolve hostname $host\n";
|
PeerHost => $host,
|
||||||
}
|
PeerPort => $port,
|
||||||
my $ip = inet_ntoa $packed_ip;
|
Proto => "tcp" )
|
||||||
|
or die "$0: Could not connect to $host: $@\n";
|
||||||
|
|
||||||
print STDERR "MOSH IP $ip\n";
|
print STDERR "MOSH IP ", $sock->peerhost, "\n";
|
||||||
|
|
||||||
# Act like netcat
|
# Act like netcat
|
||||||
my $sock = IO::Socket::INET->new( PeerAddr => $ip,
|
|
||||||
PeerPort => $port,
|
|
||||||
Proto => "tcp" )
|
|
||||||
or die "$0: connect to host $ip port $port: $!\n";
|
|
||||||
binmode($sock);
|
binmode($sock);
|
||||||
binmode(STDIN);
|
binmode(STDIN);
|
||||||
binmode(STDOUT);
|
binmode(STDOUT);
|
||||||
|
|||||||
Reference in New Issue
Block a user