open (Net::SSH::Proxy::SOCKS5)

    # File lib/net/ssh/proxy/socks5.rb, line 66
            def open( host, port )
              sock = TCPSocket.new( @proxy_host, @proxy_port )

              methods = [ SOCKS_METHOD_NO_AUTH ]
              methods << SOCKS_METHOD_PASSWD if proxy_user

              packet = [ SOCKS_VERSION, methods.size, *methods ].pack( "C*" )
              sock.send packet, 0

              version, method = sock.recv( 2 ).unpack( "CC" )
              if version != 5
                sock.close
                raise Net::SSH::Proxy::Error,
                  "invalid SOCKS version (#{version})"
              end

              if method == SOCKS_METHOD_NONE
                sock.close
                raise Net::SSH::Proxy::Error,
                  "no supported authorization methods"
              end

              case method
                when SOCKS_METHOD_NO_AUTH
                  # no method-dependent subnegotiation required

                when SOCKS_METHOD_PASSWD
                  negotiate_password( sock )
              end

              packet = [ SOCKS_VERSION, SOCKS_CMD_CONNECT, 0 ].pack( "C*" )

              if host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
                packet << [ SOCKS_ATYP_IPV4, $1.to_i, $2.to_i,
                            $3.to_i, $4.to_i ].pack( "C*" )
              else
                packet << [ SOCKS_ATYP_DOMAIN, host.length, host ].pack( "CCA*" )
              end

              packet << [ port ].pack( "n" )
              sock.send packet, 0

              version, reply, = sock.recv( 4 ).unpack( "C*" )
              len = sock.recv( 1 )[0]
              sock.recv( len + 2 )

              unless reply == SOCKS_SUCCESS
                sock.close
                raise ConnectError, "#{reply}"
              end

              return sock
            end