Module: Ronin::Network::UNIX
- Included in:
- Mixins::UNIX, Support
- Defined in:
- lib/ronin/network/unix.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.
-
#unix_session(path) {|socket| ... } ⇒ Object
Temporarily connects to a UNIX socket.
Instance Method Details
#unix_accept(path) {|client| ... } ⇒ Object
Opens a UNIX socket, accepts a connection, then closes the socket.
276 277 278 279 280 281 282 283 |
# File 'lib/ronin/network/unix.rb', line 276 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.
83 84 85 86 87 88 |
# File 'lib/ronin/network/unix.rb', line 83 def unix_connect(path) socket = UNIXSocket.new(path) yield socket if block_given? return socket end |
#unix_connect_and_send(data, path) {|socket| ... } ⇒ UNIXSocket
Connects to a UNIX Socket and sends the given data.
110 111 112 113 114 115 116 |
# File 'lib/ronin/network/unix.rb', line 110 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.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ronin/network/unix.rb', line 48 def unix_open?(path,timeout=nil) timeout ||= 5 begin Timeout.timeout(timeout) { unix_session(path) } 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.
165 166 167 168 169 170 171 |
# File 'lib/ronin/network/unix.rb', line 165 def unix_send(data,path) unix_session(path) do |socket| socket.write(data) end return true end |
#unix_server(path) {|server| ... } ⇒ UNIXServer
Opens a UNIX socket.
195 196 197 198 199 200 |
# File 'lib/ronin/network/unix.rb', line 195 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.
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/ronin/network/unix.rb', line 246 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.
221 222 223 224 225 |
# File 'lib/ronin/network/unix.rb', line 221 def unix_server_session(path,&block) socket = unix_server(path,&block) socket.close return nil end |
#unix_session(path) {|socket| ... } ⇒ Object
Temporarily connects to a UNIX socket.
137 138 139 140 141 142 143 |
# File 'lib/ronin/network/unix.rb', line 137 def unix_session(path) socket = unix_connect(path) yield socket if block_given? socket.close return nil end |