Sha256: 98e6b27ca9ca62b7372f94da8b50918688ac0b8ad038f07da7d31af4fb91df18

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

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

###
#
# This class provides methods for interacting with a TCP server.  It
# implements the SSLScan::IO::StreamServer interface.
#
###
module  SSLScan::Socket::TcpServer

  include SSLScan::Socket
  include SSLScan::IO::StreamServer

  ##
  #
  # Factory
  #
  ##

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

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

  #
  # Accepts a child connection.
  #
  def accept(opts = {})
    t = super()

    # jRuby compatibility
    if t.respond_to?('[]')
      t = t[0]
    end

    if (t)
      t.extend(SSLScan::Socket::Tcp)
      t.context = self.context

      pn = t.getpeername

      t.peerhost = pn[1]
      t.peerport = pn[2]
    end

    t
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

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