Sha256: 655f40d4e4a2c2120aa9021e8bb2e6425733f63f433a54b67466dba2f6d91d79

Contents?: true

Size: 1.22 KB

Versions: 23

Compression:

Stored size: 1.22 KB

Contents

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

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

  include Rex::Socket
  include Rex::IO::StreamServer

  ##
  #
  # Factory
  #
  ##

  #
  # Creates the server using the supplied hash.
  #
  def self.create(hash = {})
    hash['Proto'] = 'tcp'
    hash['Server'] = true
    self.create_param(Rex::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
    Rex::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(Rex::Socket::Tcp)
      t.context = self.context

      pn = t.getpeername_as_array

      # We hit a "getpeername(2)" from Ruby
      return nil unless pn

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

    t
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rex-socket-0.1.22 lib/rex/socket/tcp_server.rb
rex-socket-0.1.21 lib/rex/socket/tcp_server.rb
rex-socket-0.1.20 lib/rex/socket/tcp_server.rb
rex-socket-0.1.19 lib/rex/socket/tcp_server.rb
rex-socket-0.1.18 lib/rex/socket/tcp_server.rb
rex-socket-0.1.17 lib/rex/socket/tcp_server.rb
rex-socket-0.1.16 lib/rex/socket/tcp_server.rb
rex-socket-0.1.15 lib/rex/socket/tcp_server.rb
rex-socket-0.1.14 lib/rex/socket/tcp_server.rb
rex-socket-0.1.13 lib/rex/socket/tcp_server.rb
rex-socket-0.1.12 lib/rex/socket/tcp_server.rb
rex-socket-0.1.11 lib/rex/socket/tcp_server.rb
rex-socket-0.1.10 lib/rex/socket/tcp_server.rb
rex-socket-0.1.9 lib/rex/socket/tcp_server.rb
rex-socket-0.1.8 lib/rex/socket/tcp_server.rb
rex-socket-0.1.7 lib/rex/socket/tcp_server.rb
rex-socket-0.1.6 lib/rex/socket/tcp_server.rb
rex-socket-0.1.5 lib/rex/socket/tcp_server.rb
rex-socket-0.1.4 lib/rex/socket/tcp_server.rb
rex-socket-0.1.3 lib/rex/socket/tcp_server.rb