Sha256: 882b76256bbaf221403bc1e4e04b42f37c47c61df0553b2e29f76dae979afbc9

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

# -*- coding: binary -*-
require 'ssl_scan/socket'
require 'ssl_scan/io/stream'

###
#
# This class provides methods for interacting with a TCP client connection.
#
###
module SSLScan::Socket::Tcp

  include SSLScan::Socket
  include SSLScan::IO::Stream

  ##
  #
  # Factory
  #
  ##

  #
  # Creates the client using the supplied hash.
  #
  # @see create_param
  # @see SSLScan::Socket::Parameters.from_hash
  def self.create(hash = {})
    hash['Proto'] = 'tcp'
    self.create_param(SSLScan::Socket::Parameters.from_hash(hash))
  end

  #
  # Wrapper around the base socket class' creation method that automatically
  # sets the parameter's protocol to TCP.
  #
  def self.create_param(param)
    param.proto = 'tcp'
    SSLScan::Socket.create_param(param)
  end

  ##
  #
  # Stream mixin implementations
  #
  ##

  #
  # Calls shutdown on the TCP connection.
  #
  def shutdown(how = ::Socket::SHUT_RDWR)
    begin
      return (super(how) == 0)
    rescue ::Exception
    end
  end

  #
  # Returns peer information (host + port) in host:port format.
  #
  def peerinfo
    if (pi = getpeername)
      return pi[1] + ':' + pi[2].to_s
    end
  end

  #
  # Returns local information (host + port) in host:port format.
  #
  def localinfo
    if (pi = getlocalname)
      return pi[1] + ':' + pi[2].to_s
    end
  end

  # returns socket type
  def type?
    return 'tcp'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ssl_scan-0.0.2 lib/ssl_scan/socket/tcp.rb
ssl_scan-0.0.1 lib/ssl_scan/socket/tcp.rb