--- /usr/bin/mosh 2018-02-05 16:51:10.000000000 +0000 +++ fs2mosh 2019-07-28 10:54:53.301725339 +0100 @@ -187,7 +187,9 @@ } if ( not grep { $_ eq $use_remote_ip } qw { local remote proxy } ) { - die "Unknown parameter $use_remote_ip"; + if ($use_remote_ip !~ /^gateway:/) { + die "Unknown parameter $use_remote_ip"; + } } $family = lc( $family ); @@ -432,6 +434,23 @@ } waitpid $pid, 0; close $pipe; + + if ( $use_remote_ip =~ '^gateway:(.*)$' ) { + # "parse" the host from what the user gave us + my $shost = $1; + # get list of addresses + my @res = resolvename( $shost, 22, $family ); + # Use only the first address as the Mosh IP + my $hostaddr = $res[0]; + if ( !defined $hostaddr ) { + die( "could not find address for gateway host $shost" ); + } + my ( $err, $addr_string, $service ) = getnameinfo( $hostaddr->{addr}, NI_NUMERICHOST ); + if ( $err ) { + die( "could not use address for gateway host $shost" ); + } + $ip = $addr_string; + } if ( not defined $ip ) { if ( defined $sship ) {