#!/bin/bash

function usage()
{
  echo "usage:"
  echo "  $0 <dst_host> <dst_port> <next_hop> [proxy_port]"
  exit -1;
}

if [ "$#" -le "4" ] ; then usage ; fi

# First argument is dst host
dst_host=$1

# Second argument is dst port
dst_port=$2

# Third argument is next hop
next_hop=$3

# Fourth (and optional) argument is proxy port
proxy_port=${dst_port}

if [ "$#" -eq "4" ] ; then proxy_port=$4 ; fi

ssh -fNL ${proxy_port}:${dst_host}:${dst_port} ${next_hop}
