Class: Jruby::Pcap::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby-pcap/packet.rb

Instance Method Summary collapse

Constructor Details

#initialize(packet, handle) ⇒ Packet

Returns a new instance of Packet.



6
7
8
9
# File 'lib/jruby-pcap/packet.rb', line 6

def initialize(packet, handle)
  @packet = packet
  @handle = handle
end

Instance Method Details

#ipv4Object



15
16
17
18
# File 'lib/jruby-pcap/packet.rb', line 15

def ipv4
  dataset = @packet.get(IpV4Packet)
  Frame.new( @handle, dataset ) if dataset
end

#tcpObject



25
26
27
28
# File 'lib/jruby-pcap/packet.rb', line 25

def tcp
  dataset = @packet.get(TcpPacket)
  Frame.new( @handle, dataset ) if dataset
end

#timestampObject



11
12
13
# File 'lib/jruby-pcap/packet.rb', line 11

def timestamp
  @handle.get_timestamp_ints * 1000
end

#to_hashObject



30
31
32
33
34
35
36
# File 'lib/jruby-pcap/packet.rb', line 30

def to_hash
  hash  = {}
  hash.merge!(ipv4.to_hash) if ipv4
  hash.merge!(tcp.to_hash)  if tcp
  hash.merge!(udp.to_hash)  if udp
  hash
end

#to_sObject



38
39
40
# File 'lib/jruby-pcap/packet.rb', line 38

def to_s
  @packet.to_s
end

#udpObject



20
21
22
23
# File 'lib/jruby-pcap/packet.rb', line 20

def udp
  dataset = @packet.get(UdpPacket)
  Frame.new( @handle, dataset ) if dataset
end