aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorGravatar John Hood <cgull@glup.org>2016-06-10 11:58:29 -0400
committerGravatar John Hood <cgull@glup.org>2016-07-10 23:30:24 -0400
commitaf8ddd090e8a702063791ab3965a53b4f9818906 (patch)
tree1cd746eb05ac68553d82ad39c90bf1f51e551a13 /scripts
parent1b2ddc2e81b3b0b29a26d8821bcabf96043eb11c (diff)
Add options to prefer v4 or v6 on connect; make prefer-inet the default.
Resolves #764, mostly.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mosh.pl17
1 files changed, 12 insertions, 5 deletions
diff --git a/scripts/mosh.pl b/scripts/mosh.pl
index f60ebce..dc735b1 100755
--- a/scripts/mosh.pl
+++ b/scripts/mosh.pl
@@ -63,7 +63,7 @@ my $bind_ip = undef;
my $use_remote_ip = 'proxy';
-my $family = 'all';
+my $family = 'prefer-inet';
my $port_request = undef;
my @ssh = ('ssh');
@@ -91,8 +91,10 @@ qq{Usage: $0 [options] [--] [user@]host [command...]
-4 --family=inet use IPv4 only
-6 --family=inet6 use IPv6 only
- --family=auto autodetect network type for single-family hosts
- --family=all try all network types [default]
+ --family=auto autodetect network type for single-family hosts only
+ --family=all try all network types
+ --family=prefer-inet use all network types, but try IPv4 first [default]
+ --family=prefer-inet6 use all network types, but try IPv6 first
-p PORT[:PORT2]
--port=PORT[:PORT2] server-side UDP port or range
--bind-server={ssh|any|IP} ask the server to reply from an IP address
@@ -453,7 +455,7 @@ sub resolvename {
my $af;
# If the user selected a specific family, parse it.
- if ( defined( $family ) && ( $family ne "auto" && $family ne "all" )) {
+ if ( defined( $family ) && ( $family eq 'inet' || $family eq 'inet6' )) {
# Choose an address family, or cause pain.
my $afstr = 'AF_' . uc( $family );
$af = eval { IO::Socket->$afstr } or die "$0: Invalid family $family\n";
@@ -480,9 +482,14 @@ sub resolvename {
@res = @newres;
}
- # If v4 or v6 was specified, reduce the host list.
if ( defined( $af )) {
+ # If v4 or v6 was specified, reduce the host list.
@res = grep {$_->{family} == $af} @res;
+ } elsif ( $family =~ /^prefer-/ ) {
+ # If prefer-* was specified, reorder the host list to put that family first.
+ my $prefer_afstr = 'AF_' . uc( ($family =~ /prefer-(.*)/)[0] );
+ my $prefer_af = eval { IO::Socket->$prefer_afstr } or die "$0: Invalid preferred family $family\n";
+ @res = (grep({$_->{family} == $prefer_af} @res), grep({$_->{family} != $prefer_af} @res));
} elsif ( $family ne 'all' ) {
# If v4/v6/all were not specified, verify that this host only has one address family available.
for my $ai ( @res ) {