Method: Net::SSH::Proxy::SOCKS4#open
- Defined in:
- lib/net/ssh/proxy/socks4.rb
#open(host, port) ⇒ Object
Return a new socket connected to the given host and port via the proxy that was requested when the socket factory was instantiated.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/net/ssh/proxy/socks4.rb', line 50 def open(host, port) socket = TCPSocket.new(proxy_host, proxy_port) ip_addr = IPAddr.new(Resolv.getaddress(host)) packet = [VERSION, CONNECT, port.to_i, ip_addr.to_i, [:user]].pack("CCnNZ*") socket.send packet, 0 version, status, port, ip = socket.recv(8).unpack("CCnN") if status != GRANTED socket.close raise ConnectError, "error connecting to proxy (#{status})" end return socket end |