Class: SimpleCapture::RecvMessageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_capture/recv_message.rb

Instance Method Summary collapse

Constructor Details

#initialize(mesg) ⇒ RecvMessageHandler

Returns a new instance of RecvMessageHandler.



3
4
5
# File 'lib/simple_capture/recv_message.rb', line 3

def initialize(mesg)
  @mesg = mesg
end

Instance Method Details

#to_packetPacket

Returns:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_capture/recv_message.rb', line 8

def to_packet
  headers = []
  ether = SimpleCapture::EtherHeader.new(bytes: @mesg.bytes[0..13])
  headers.push(ether)

  if ether.upper_layer_protocol_ipv4?
    ip = SimpleCapture::IPv4Header.new(bytes: @mesg.bytes[14..33])
    headers.push(ip)
    if ip.upper_layer_protocol_icmp?
      icmp =  SimpleCapture::ICMPHeader.new(bytes: @mesg.bytes[34..(@mesg.bytes.size-1)])
      headers.push(icmp)
    end
  end
  SimpleCapture::Packet.new(headers)
end