Class: PacketFu::Timestamp
- Includes:
- StructFu
- Defined in:
- lib/packetfu/pcap.rb
Overview
The Timestamp class defines how Timestamps appear in libpcap files.
Header Definition
Symbol :endian Default: :little
Int32 :sec
Int32 :usec
Instance Attribute Summary collapse
-
#endian ⇒ Object
Returns the value of attribute endian.
-
#sec ⇒ Object
Returns the value of attribute sec.
-
#usec ⇒ Object
Returns the value of attribute usec.
Instance Method Summary collapse
-
#init_fields(args = {}) ⇒ Object
Called by initialize to set the initial fields.
-
#initialize(args = {}) ⇒ Timestamp
constructor
A new instance of Timestamp.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_s ⇒ Object
Returns the object in string form.
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ Timestamp
Returns a new instance of Timestamp.
111 112 113 114 115 |
# File 'lib/packetfu/pcap.rb', line 111 def initialize(args={}) set_endianness(args[:endian] ||= :little) init_fields(args) super(args[:endian], args[:sec], args[:usec]) end |
Instance Attribute Details
#endian ⇒ Object
Returns the value of attribute endian
108 109 110 |
# File 'lib/packetfu/pcap.rb', line 108 def endian @endian end |
#sec ⇒ Object
Returns the value of attribute sec
108 109 110 |
# File 'lib/packetfu/pcap.rb', line 108 def sec @sec end |
#usec ⇒ Object
Returns the value of attribute usec
108 109 110 |
# File 'lib/packetfu/pcap.rb', line 108 def usec @usec end |
Instance Method Details
#init_fields(args = {}) ⇒ Object
Called by initialize to set the initial fields.
118 119 120 121 122 |
# File 'lib/packetfu/pcap.rb', line 118 def init_fields(args={}) args[:sec] = @int32.new(args[:sec]) args[:usec] = @int32.new(args[:usec]) return args end |
#read(str) ⇒ Object
Reads a string to populate the object.
130 131 132 133 134 135 136 |
# File 'lib/packetfu/pcap.rb', line 130 def read(str) force_binary(str) return self if str.nil? self[:sec].read str[0,4] self[:usec].read str[4,4] self end |
#to_s ⇒ Object
Returns the object in string form.
125 126 127 |
# File 'lib/packetfu/pcap.rb', line 125 def to_s self.to_a[1,2].map {|x| x.to_s}.join end |