Class: PcapParser::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/pcap_parser/packet.rb

Overview

Per-packet header of pcap file See: www.tcpdump.org/manpages/pcap-savefile.5.txt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Packet

Returns a new instance of Packet


6
7
8
9
10
11
12
# File 'lib/pcap_parser/packet.rb', line 6

def initialize(stream)
  @sec,
  @sec_frac,
  @cap_len,
  @orig_len = stream.read_int32(4)
  @sec_subt = stream.sec_subt
end

Instance Attribute Details

#cap_lenObject (readonly)

Returns the value of attribute cap_len


5
6
7
# File 'lib/pcap_parser/packet.rb', line 5

def cap_len
  @cap_len
end

#orig_lenObject (readonly)

Returns the value of attribute orig_len


5
6
7
# File 'lib/pcap_parser/packet.rb', line 5

def orig_len
  @orig_len
end

#secObject (readonly)

Returns the value of attribute sec


5
6
7
# File 'lib/pcap_parser/packet.rb', line 5

def sec
  @sec
end

Instance Method Details

#nsecInteger

Convert timestamp fraction to nanoseconds

Returns:

  • (Integer)

    nanoseconds


22
23
24
# File 'lib/pcap_parser/packet.rb', line 22

def nsec
  (@sec_frac.to_f * @sec_subt / 10**-9).round
end

#usecInteger

Convert timestamp fraction to microseconds

Returns:

  • (Integer)

    microseconds


16
17
18
# File 'lib/pcap_parser/packet.rb', line 16

def usec
  (@sec_frac.to_f * @sec_subt / 10**-6).round
end