diff options
author | Anders Kaseorg <andersk@mit.edu> | 2013-08-15 08:33:49 -0400 |
---|---|---|
committer | Anders Kaseorg <andersk@mit.edu> | 2013-08-17 09:02:45 -0400 |
commit | aeee659c2841a19de7c0bd94a0f42bbfd3f7c79b (patch) | |
tree | e4e6a0bebc6fa48f41b28009dccb70a14246343c /scripts | |
parent | 553918d3f2f9e944d7ea475756309f3ac3bc122b (diff) |
scripts/mosh: Let IO::Socket resolve the hostname
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mosh | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/scripts/mosh b/scripts/mosh index 4e8b796..3e6359e 100755 --- a/scripts/mosh +++ b/scripts/mosh @@ -34,8 +34,8 @@ my $MOSH_VERSION = '1.2.4a'; use warnings; use strict; -use Socket; use Getopt::Long; +use IO::Socket; $|=1; @@ -168,25 +168,21 @@ if ( not defined $bind_ip or $bind_ip =~ m{^ssh$}i ) { if ( defined $fake_proxy ) { use Errno qw(EINTR); - use IO::Socket::INET; use POSIX qw(_exit); my ( $host, $port ) = @ARGV; - # Resolve hostname - my $packed_ip = gethostbyname $host; - if ( not defined $packed_ip ) { - die "$0: Could not resolve hostname $host\n"; - } - my $ip = inet_ntoa $packed_ip; + # Resolve hostname and connect + my $sock = IO::Socket->new( Domain => AF_INET, + Family => AF_INET, + PeerHost => $host, + PeerPort => $port, + 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 - 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(STDIN); binmode(STDOUT); |