Class: PacketFu::Timestamp

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Methods included from StructFu

#body=, #clone, #set_endianness, #sz, #typecast

Methods inherited from Struct

#force_binary

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

#endianObject

Returns the value of attribute endian

Returns:

  • (Object)

    the current value of endian



108
109
110
# File 'lib/packetfu/pcap.rb', line 108

def endian
  @endian
end

#secObject

Returns the value of attribute sec

Returns:

  • (Object)

    the current value of sec



108
109
110
# File 'lib/packetfu/pcap.rb', line 108

def sec
  @sec
end

#usecObject

Returns the value of attribute usec

Returns:

  • (Object)

    the current value of 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_sObject

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