Sha256: b7938df99f56b896b297b33b6753d0cd3a250e0ebfedc08997c3c7d4d03ce3c8

Contents?: true

Size: 1.33 KB

Versions: 15

Compression:

Stored size: 1.33 KB

Contents

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

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

  include Rex::Socket
  include Rex::IO::Stream

  ##
  #
  # Factory
  #
  ##

  #
  # Creates the client using the supplied hash.
  #
  # @see create_param
  # @see Rex::Socket::Parameters.from_hash
  def self.create(hash = {})
    hash['Proto'] = 'tcp'
    self.create_param(Rex::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'
    Rex::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

15 entries across 15 versions & 3 rubygems

Version Path
rex-2.0.13 lib/rex/socket/tcp.rb
rex-2.0.12 lib/rex/socket/tcp.rb
rex-2.0.11 lib/rex/socket/tcp.rb
rex-2.0.10 lib/rex/socket/tcp.rb
rex-2.0.9 lib/rex/socket/tcp.rb
rex-2.0.8 lib/rex/socket/tcp.rb
rex-2.0.7 lib/rex/socket/tcp.rb
rex-2.0.5 lib/rex/socket/tcp.rb
rex-2.0.4 lib/rex/socket/tcp.rb
dstruct-0.0.1 lib/rex/socket/tcp.rb
rex-2.0.3 lib/rex/socket/tcp.rb
librex-0.0.999 lib/rex/socket/tcp.rb
rex-2.0.2 lib/rex/socket/tcp.rb
librex-0.0.71 lib/rex/socket/tcp.rb
librex-0.0.70 lib/rex/socket/tcp.rb