Sha256: a87512f40db2470be082f73fd177c359e3317e735e09a9127309f35f11932937

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require_relative "./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

1 entries across 1 versions & 1 rubygems

Version Path
proxifier-fork-1.1.0 lib/proxifier/proxies/socks4.rb