2005-06-02 07:52:17 +00:00
|
|
|
require 'Rex/Socket'
|
|
|
|
require 'Rex/IO/Stream'
|
|
|
|
|
2005-06-03 07:32:17 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# Tcp
|
|
|
|
# ---
|
|
|
|
#
|
|
|
|
# This class provides methods for interacting with a TCP client connection.
|
|
|
|
#
|
|
|
|
###
|
2005-06-02 07:52:17 +00:00
|
|
|
class Rex::Socket::Tcp < Rex::Socket
|
|
|
|
include Rex::IO::Stream
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
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
|
|
|
|
|
|
|
#
|
|
|
|
# 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'
|
|
|
|
|
2005-06-03 07:37:15 +00:00
|
|
|
super(param)
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Stream mixin implementations
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
def write(buf, opts = {})
|
|
|
|
return sock.syswrite(buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(length = nil, opts = {})
|
|
|
|
length = 16384 unless length
|
|
|
|
|
|
|
|
begin
|
|
|
|
return sock.sysread(length)
|
|
|
|
rescue EOFError
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-03 05:21:49 +00:00
|
|
|
def shutdown(how = SHUT_RDWR)
|
|
|
|
return (sock.shutdown(how) == 0)
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
2005-06-03 07:13:15 +00:00
|
|
|
def has_read_data?(timeout = nil)
|
|
|
|
timeout = timeout.to_i if (timeout)
|
2005-06-02 07:52:17 +00:00
|
|
|
|
2005-06-03 07:13:15 +00:00
|
|
|
return (select([ poll_fd ], nil, nil, timeout) != nil)
|
2005-06-02 07:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|