2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/socket'
|
|
|
|
require 'rex/io/stream'
|
2005-06-02 07:52:17 +00:00
|
|
|
|
2005-06-03 07:32:17 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class provides methods for interacting with a TCP client connection.
|
|
|
|
#
|
|
|
|
###
|
2005-09-27 05:31:48 +00:00
|
|
|
module Rex::Socket::Tcp
|
2005-07-15 23:46:05 +00:00
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
include Rex::Socket
|
2005-06-02 07:52:17 +00:00
|
|
|
include Rex::IO::Stream
|
2005-09-27 05:31:48 +00:00
|
|
|
|
2005-06-02 07:52:17 +00:00
|
|
|
##
|
|
|
|
#
|
2005-06-03 07:13:15 +00:00
|
|
|
# Factory
|
2005-06-02 07:52:17 +00:00
|
|
|
#
|
|
|
|
##
|
2005-06-03 07:13:15 +00:00
|
|
|
|
2005-07-17 07:43:24 +00:00
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Creates the client using the supplied hash.
|
2005-07-17 07:43:24 +00:00
|
|
|
#
|
|
|
|
def self.create(hash)
|
|
|
|
self.create_param(Rex::Socket::Parameters.from_hash(hash))
|
|
|
|
end
|
|
|
|
|
2005-06-03 07:13:15 +00:00
|
|
|
#
|
|
|
|
# Wrapper around the base socket class' creation method that automatically
|
2005-11-15 05:22:13 +00:00
|
|
|
# sets the parameter's protocol to TCP.
|
2005-06-03 07:13:15 +00:00
|
|
|
#
|
|
|
|
def self.create_param(param)
|
|
|
|
param.proto = 'tcp'
|
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
Rex::Socket.create_param(param)
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Stream mixin implementations
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-07-16 08:12:58 +00:00
|
|
|
#
|
|
|
|
# Calls shutdown on the TCP connection.
|
|
|
|
#
|
2005-06-03 05:21:49 +00:00
|
|
|
def shutdown(how = SHUT_RDWR)
|
2005-07-18 23:32:34 +00:00
|
|
|
begin
|
2005-09-27 05:31:48 +00:00
|
|
|
return (super(how) == 0)
|
2005-07-18 23:32:34 +00:00
|
|
|
rescue Errno::ENOTCONN
|
|
|
|
end
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
2005-07-16 08:12:58 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2006-01-27 05:33:08 +00:00
|
|
|
# returns socket type
|
|
|
|
def type?
|
|
|
|
return 'tcp'
|
|
|
|
end
|
2005-12-13 06:08:40 +00:00
|
|
|
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|