Module: Rex::Socket::TcpServer
- Includes:
- IO::StreamServer, Rex::Socket
- Included in:
- SslTcpServer
- Defined in:
- lib/rex/socket/tcp_server.rb
Overview
This class provides methods for interacting with a TCP server. It implements the Rex::IO::StreamServer interface.
Constant Summary
Constants included from Rex::Socket
LogSource, MATCH_IPV4, MATCH_IPV4_PRIVATE, MATCH_IPV6, MATCH_MAC_ADDR, VERSION
Instance Attribute Summary
Attributes included from Rex::Socket
#context, #ipv, #localhost, #localport, #peerhost, #peerhostname, #peerport
Class Method Summary collapse
-
.create(hash = {}) ⇒ Object
Creates the server using the supplied hash.
-
.create_param(param) ⇒ Object
Wrapper around the base class' creation method that automatically sets the parameter's protocol to TCP and sets the server flag to true.
Instance Method Summary collapse
-
#accept(opts = {}) ⇒ Object
Accepts a child connection.
Methods included from Rex::Socket
addr_atoc, addr_atoi, addr_atoi_list, addr_aton, addr_ctoa, addr_itoa, addr_iton, addr_ntoa, addr_ntoi, bit2netmask, cidr_crack, compress_address, create_ip, create_tcp, create_tcp_server, create_udp, dotted_ip?, eth_aton, eth_ntoa, #fd, from_sockaddr, getaddress, getaddresses, gethostbyname, #getlocalname, #getpeername_as_array, #getsockname, #initsock, ipv6_link_address, ipv6_mac, is_internal?, is_ip_addr?, is_ipv4?, is_ipv6?, is_mac_addr?, #localinfo, net2bitmask, #peerinfo, portlist_to_portspec, portspec_crack, portspec_to_portlist, resolv_nbo, resolv_nbo_i, resolv_nbo_i_list, resolv_nbo_list, resolv_to_dotted, source_address, support_ipv6?, tcp_socket_pair, to_sockaddr, #type?, udp_socket_pair
Class Method Details
.create(hash = {}) ⇒ Object
Creates the server using the supplied hash.
26 27 28 29 30 |
# File 'lib/rex/socket/tcp_server.rb', line 26 def self.create(hash = {}) hash['Proto'] = 'tcp' hash['Server'] = true self.create_param(Rex::Socket::Parameters.from_hash(hash)) end |
.create_param(param) ⇒ Object
Wrapper around the base class' creation method that automatically sets the parameter's protocol to TCP and sets the server flag to true.
36 37 38 39 40 |
# File 'lib/rex/socket/tcp_server.rb', line 36 def self.create_param(param) param.proto = 'tcp' param.server = true Rex::Socket.create_param(param) end |
Instance Method Details
#accept(opts = {}) ⇒ Object
Accepts a child connection.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rex/socket/tcp_server.rb', line 45 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] ln = t.getlocalname t.localhost = ln[1] t.localport = ln[2] end t end |