module HTTPX::Plugins::Proxy::Socks4::Packet

  1. lib/httpx/plugins/proxy/socks4.rb

Methods

Public Instance

  1. connect

Public Instance methods

connect (parameters, uri)
[show source]
    # File lib/httpx/plugins/proxy/socks4.rb
 95 def connect(parameters, uri)
 96   packet = [VERSION, CONNECT, uri.port].pack("CCn")
 97   begin
 98     ip = IPAddr.new(uri.host)
 99     raise Error, "Socks4 connection to #{ip} not supported" unless ip.ipv4?
100 
101     packet << [ip.to_i].pack("N")
102   rescue IPAddr::InvalidAddressError
103     if parameters.uri.scheme == "socks4"
104       # resolv defaults to IPv4, and socks4 doesn't support IPv6 otherwise
105       ip = IPAddr.new(Resolv.getaddress(uri.host))
106       packet << [ip.to_i].pack("N")
107     else
108       packet << "\x0\x0\x0\x1" << "\x7\x0" << uri.host
109     end
110   end
111   packet << [parameters.username].pack("Z*")
112   packet
113 end