lib/ronin/network/udp/proxy.rb in ronin-support-0.5.0.rc2 vs lib/ronin/network/udp/proxy.rb in ronin-support-0.5.0

- old
+ new

@@ -23,10 +23,32 @@ module Ronin module Network module UDP # + # The UDP Proxy allows for inspecting and manipulating UDP protocols. + # + # ## Example + # + # require 'ronin/network/udp/proxy' + # require 'hexdump' + # + # Ronin::Network::UDP::Proxy.start(:port => 1337, :server => ['4.2.2.1', 53]) do |proxy| + # hex = Hexdump::Dumper.new + # + # proxy.on_client_data do |(client,(host,port)),server,data| + # puts "#{host}:#{port} -> #{proxy}" + # hex.dump(data) + # end + # + # proxy.on_server_data do |(client,(host,port)),server,data| + # puts "#{host}:#{port} <- #{proxy}" + # hex.dump(data) + # end + # + # end + # # @since 0.5.0 # class Proxy < Network::Proxy # @@ -49,17 +71,17 @@ sockets = [@socket] + server_connections readable, writtable, errors = IO.select(sockets,nil,sockets) (errors & server_connections).each do |server_socket| - client_socket = client_for(server_socket) + client_socket = client_connection_for(server_socket) close_connection(client_socket,server_socket) end (readable & server_connections).each do |server_socket| - client_socket = client_for(server_socket) + client_socket = client_connection_for(server_socket) data, addrinfo = recv(server_socket) server_data(client_socket,server_socket,data) end @@ -113,10 +135,10 @@ when Array socket, (host, port) = connection socket.recvfrom(@buffer_size) when UDPSocket - socket.recv(@buffer_size) + connection.recvfrom(@buffer_size) end end protected