Skip to content

Commit

Permalink
Merge pull request igrigorik#2 from meh/master
Browse files Browse the repository at this point in the history
Add support for connection by unresolvable hostname (Tor support)
  • Loading branch information
igrigorik committed Sep 28, 2011
2 parents 18eee6e + e6d0aa8 commit b6b387b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/em-socksify/socksify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ def send_socks_handshake
end

def send_socks_connect_request
begin
# TO-DO: Implement address types for IPv6 and Domain
ip_address = Socket.gethostbyname(@host).last
send_data [5, 1, 0, 1, ip_address, @port].flatten.pack('CCCCA4n')
send_data [5, 1, 0].pack('CCC')

begin
# TODO: Implement address types for IPv6 and Domain
# TODO: resolve domain through the proxy
send_data [1, Socket.gethostbyname(@host).last].pack('CA4')
rescue
fail("could not resolve host")
send_data [3, @host.size, @host].pack('CCA*')
end

send_data [@port].pack('n')
end

private
Expand Down Expand Up @@ -119,4 +122,4 @@ def socks_methods
end

end
end
end

0 comments on commit b6b387b

Please sign in to comment.