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