Class: Phut::RawSocket
- Inherits:
-
Object
- Object
- Phut::RawSocket
- Defined in:
- lib/phut/raw_socket.rb
Overview
raw socket
Constant Summary collapse
- ETH_P_ALL =
0x0300
- SIOCGIFINDEX =
0x8933
Instance Method Summary collapse
-
#initialize(interface) ⇒ RawSocket
constructor
A new instance of RawSocket.
-
#method_missing(method, *args) ⇒ Object
rubocop:disable MethodMissing.
Constructor Details
#initialize(interface) ⇒ RawSocket
Returns a new instance of RawSocket.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phut/raw_socket.rb', line 11 def initialize(interface) @socket = Socket.new(Socket::PF_PACKET, Socket::SOCK_RAW, ETH_P_ALL).tap do |sock| ifreq = [interface].pack('a32') sock.ioctl SIOCGIFINDEX, ifreq sock.bind([Socket::AF_PACKET].pack('s').tap do |sll| sll << ([ETH_P_ALL].pack 's') sll << ifreq[16..20] sll << ("\x00" * 12) end) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
rubocop:disable MethodMissing
25 26 27 |
# File 'lib/phut/raw_socket.rb', line 25 def method_missing(method, *args) @socket.__send__ method, *args end |