Module: Ronin::Support::Network::UNIX::Mixin
- Included in:
- Mixin
- Defined in:
- lib/ronin/support/network/unix/mixin.rb
Overview
Provides helper methods for communicating with UNIX sockets.
Instance Method Summary collapse
-
#unix_accept(path) {|client| ... } ⇒ Object
Opens a UNIX socket, accepts a connection, then closes the socket.
-
#unix_connect(path) {|socket| ... } ⇒ UNIXSocket?
Connects to a UNIX socket.
-
#unix_connect_and_send(data, path) {|socket| ... } ⇒ UNIXSocket
Connects to a UNIX Socket and sends the given data.
-
#unix_open?(path, timeout = nil) ⇒ Boolean?
Tests whether a UNIX socket is open.
-
#unix_send(data, path) ⇒ true
Connects to a UNIX socket, sends the given data and then closes the socket.
-
#unix_server(path) {|server| ... } ⇒ UNIXServer
Opens a UNIX socket.
-
#unix_server_loop(path) {|client| ... } ⇒ Object
Opens a UNIX socket, accepts connections in a loop.
-
#unix_server_session(path) {|server| ... } ⇒ Object
Temporarily opens a UNIX socket.
Instance Method Details
#unix_accept(path) {|client| ... } ⇒ Object
Opens a UNIX socket, accepts a connection, then closes the socket.
261 262 263 264 265 266 267 268 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 261 def unix_accept(path) unix_server_session(path) do |server| client = server.accept yield client if block_given? client.close end end |
#unix_connect(path) {|socket| ... } ⇒ UNIXSocket?
Connects to a UNIX socket.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 91 def unix_connect(path) socket = UNIXSocket.new(path) if block_given? yield socket socket.close else return socket end end |
#unix_connect_and_send(data, path) {|socket| ... } ⇒ UNIXSocket
Connects to a UNIX Socket and sends the given data.
122 123 124 125 126 127 128 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 122 def unix_connect_and_send(data,path) socket = unix_connect(path) socket.write(data) yield socket if block_given? return socket end |
#unix_open?(path, timeout = nil) ⇒ Boolean?
Tests whether a UNIX socket is open.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 47 def unix_open?(path,timeout=nil) timeout ||= 5 begin Timeout.timeout(timeout) do socket = unix_connect(path) socket.close end return true rescue Timeout::Error return nil rescue SocketError, SystemCallError return false end end |
#unix_send(data, path) ⇒ true
Connects to a UNIX socket, sends the given data and then closes the socket.
150 151 152 153 154 155 156 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 150 def unix_send(data,path) unix_connect(path) do |socket| socket.write(data) end return true end |
#unix_server(path) {|server| ... } ⇒ UNIXServer
Opens a UNIX socket.
180 181 182 183 184 185 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 180 def unix_server(path) socket = UNIXServer.new(path) yield socket if block_given? return socket end |
#unix_server_loop(path) {|client| ... } ⇒ Object
Opens a UNIX socket, accepts connections in a loop.
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 231 def unix_server_loop(path) unix_server_session(path) do |server| loop do client = server.accept yield client if block_given? client.close end end end |
#unix_server_session(path) {|server| ... } ⇒ Object
Temporarily opens a UNIX socket.
206 207 208 209 210 |
# File 'lib/ronin/support/network/unix/mixin.rb', line 206 def unix_server_session(path,&block) socket = unix_server(path,&block) socket.close return nil end |