# File lib/net/ssh/service/forward.rb, line 52
    def local(*args)
      if args.length < 3 || args.length > 4
        raise ArgumentError, "expected 3 or 4 parameters, got #{args.length}"
      end

      local_port_type = :long

      socket = begin
        if defined?(UNIXServer) and args.first.class == UNIXServer
          local_port_type = :string
          args.shift
        else
          bind_address = "127.0.0.1"
          bind_address = args.shift if args.first.is_a?(String) && args.first =~ /\D/
          local_port = args.shift.to_i
          local_port_type = :long
          TCPServer.new(bind_address, local_port)
        end
      end

      remote_host = args.shift
      remote_port = args.shift.to_i

      @local_forwarded_ports[[local_port, bind_address]] = socket

      session.listen_to(socket) do |server|
        client = server.accept
        debug { "received connection on #{socket}" }

        channel = session.open_channel("direct-tcpip", :string, remote_host, :long, remote_port, :string, bind_address, local_port_type, local_port) do |achannel|
          achannel.info { "direct channel established" }
        end

        prepare_client(client, channel, :local)
  
        channel.on_open_failed do |ch, code, description|
          channel.error { "could not establish direct channel: #{description} (#{code})" }
          channel[:socket].close
        end
      end
    end