Class/Module Index [+]

Quicksearch

Rex::Ui::Text::Input::Socket

This class implements input against a socket.

Public Class Methods

new(sock) click to toggle source
# File lib/rex/ui/text/input/socket.rb, line 14
def initialize(sock)
        @sock = sock
end

Public Instance Methods

eof?() click to toggle source

Returns whether or not EOF has been reached on stdin.

# File lib/rex/ui/text/input/socket.rb, line 81
def eof?
        @sock.closed?
end
fd() click to toggle source

Returns the file descriptor associated with a socket.

# File lib/rex/ui/text/input/socket.rb, line 88
def fd
        return @sock
end
gets() click to toggle source

Wait for a line of input to be read from a socket.

# File lib/rex/ui/text/input/socket.rb, line 35
def gets

        # Initialize the line buffer
        line = ''
        
        # Read data one byte at a time until we see a LF
        while (true)

                break if line.include?("\n")
                
                # Read another character of input
                char = @sock.getc
                if char.nil?
                        @sock.close
                        return
                end
                
                # Telnet sends 0x04 as EOF
                if (char == 4)
                        @sock.write("[*] Caught ^D, closing the socket...\n")
                        @sock.close
                        return
                end
                
                # Append this character to the string
                line << char

                # Handle telnet sequences
                case line
                        when /\xff\xf4\xff\xfd\x06/
                                @sock.write("[*] Caught ^C, closing the socket...\n")
                                @sock.close
                                return
                                
                        when /\xff\xed\xff\xfd\x06/
                                @sock.write("[*] Caught ^Z\n")
                                return             
                end
        end
        
        return line
end
supports_readline() click to toggle source

Sockets do not currently support readline.

# File lib/rex/ui/text/input/socket.rb, line 21
def supports_readline
        false
end
sysread(len = 1) click to toggle source

Reads input from the raw socket.

# File lib/rex/ui/text/input/socket.rb, line 28
def sysread(len = 1)
        @sock.sysread(len)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.