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.



109
110
111
112
113
# File 'lib/packetfu/pcap.rb', line 109

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



106
107
108
# File 'lib/packetfu/pcap.rb', line 106

def endian
  @endian
end

#secObject

Returns the value of attribute sec

Returns:

  • (Object)

    the current value of sec



106
107
108
# File 'lib/packetfu/pcap.rb', line 106

def sec
  @sec
end

#usecObject

Returns the value of attribute usec

Returns:

  • (Object)

    the current value of usec



106
107
108
# File 'lib/packetfu/pcap.rb', line 106

def usec
  @usec
end

Instance Method Details

#init_fields(args = {}) ⇒ Object

Called by initialize to set the initial fields.



116
117
118
119
120
# File 'lib/packetfu/pcap.rb', line 116

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.



128
129
130
131
132
133
134
# File 'lib/packetfu/pcap.rb', line 128

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.



123
124
125
# File 'lib/packetfu/pcap.rb', line 123

def to_s
	self.to_a[1,2].map {|x| x.to_s}.join
end