Class: Pcap::Savefile::Packet

Inherits:
Object
  • Object
show all
Extended by:
EasyIO
Includes:
EasyIO
Defined in:
lib/pcap/savefile.rb

Overview

class GlobalHeader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EasyIO

i32, u16, u32, wi32, wu16, wu32

Constructor Details

#initialize(data, time = nil, orig_len = nil) ⇒ Packet

Returns a new instance of Packet.



112
113
114
115
116
# File 'lib/pcap/savefile.rb', line 112

def initialize(data, time = nil, orig_len = nil)
  @data = data
  @time = time || Time.now
  @orig_len = orig_len
end

Instance Attribute Details

#dataObject (readonly)

String



99
100
101
# File 'lib/pcap/savefile.rb', line 99

def data
  @data
end

#orig_lenObject

original length of data



102
103
104
# File 'lib/pcap/savefile.rb', line 102

def orig_len
  @orig_len || incl_len
end

#timeObject (readonly)

Time



97
98
99
# File 'lib/pcap/savefile.rb', line 97

def time
  @time
end

Class Method Details

.from_io(io) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/pcap/savefile.rb', line 130

def from_io(io)
  sec = u32(io)
  usec = u32(io)
  timestamp = Time.at(sec, usec)
  length = u32(io)
  original_length = u32(io)
  data = io.read(length)
  packet = self.new(data, timestamp, original_length)
  packet
end

Instance Method Details

#incl_lenObject

included length



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

def incl_len
  data.length
end

#write(io) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/pcap/savefile.rb', line 118

def write(io)
  u = time.getutc
  wu32(io, u.tv_sec)
  wu32(io, u.tv_usec)
  wu32(io, incl_len)
  wu32(io, orig_len)
  io.write(data)
end