Sha256: cc1d8dce72adf67cf03054ab0cc2cd1a51fbecfb8eeab9d30be8886f7717778d

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

require "proxifier/proxies/socks"

module Proxifier
  class SOCKS4Proxy < SOCKSProxy
    VERSION = 0x04

    protected
      def greet(socket)
        # noop
      end

      def authenticate(socket, method)
        # noop
      end

      def connect(socket, host, port)
        begin
          ip = IPAddr.new(host)
        rescue ArgumentError
          ip = IPAddr.new(Socket.getaddrinfo(host, nil, :INET, :STREAM).first)
        end

        socket << [VERSION, 0x01, port].pack("CCn") << ip.hton
        socket << user if user
        socket << 0x00

        version, status, port = socket.read(4).unpack("CCn")
        check_version(version, 0x00)
        ip = IPAddr.ntop(socket.read(4))

        case status
        when 0x5A # request granted
        when 0x5B # request rejected or failed
          raise "request rejected or failed"
        when 0x5C # request rejected becasue SOCKS server cannot connect to identd on the client
          raise "request rejected becasue SOCKS server cannot connect to identd on the client"
        when 0x5D # request rejected because the client program and identd report different user-ids
          raise "request rejected because the client program and identd report different user-ids"
        else
          raise "unknown SOCKS error"
        end
      end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
proxifier2-1.1.0 lib/proxifier/proxies/socks4.rb
proxifier-fork-1.0.4 lib/proxifier/proxies/socks4.rb
proxifier-1.0.3 lib/proxifier/proxies/socks4.rb
proxifier-1.0.2 lib/proxifier/proxies/socks4.rb
proxifier-1.0.1 lib/proxifier/proxies/socks4.rb
proxifier-1.0.0 lib/proxifier/proxies/socks4.rb