Class: Pcap::Savefile::GlobalHeader

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

Constant Summary collapse

MAGIC_NUMBER =
0xa1b2c3d4
VERSION_MAJOR =
2
VERSION_MINOR =
4
THIS_ZONE =

we write times in UTC

0

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(network) ⇒ GlobalHeader

Returns a new instance of GlobalHeader.



54
55
56
57
58
# File 'lib/pcap/savefile.rb', line 54

def initialize(network)
  @sigfigs = 0
  @snaplen = 65535
  @network = network
end

Instance Attribute Details

#networkObject

data link layer type



53
54
55
# File 'lib/pcap/savefile.rb', line 53

def network
  @network
end

#sigfigsObject

significant figures in time stamps



49
50
51
# File 'lib/pcap/savefile.rb', line 49

def sigfigs
  @sigfigs
end

#snaplenObject

snapshot length, packets longer than this are truncated



51
52
53
# File 'lib/pcap/savefile.rb', line 51

def snaplen
  @snaplen
end

Class Method Details

.from_io(io) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pcap/savefile.rb', line 75

def from_io(io)
  magic_number = u32(io)
  raise "Bad magic: #{magic_number}" unless magic_number == MAGIC_NUMBER
  version_major = u16(io)
  version_minor = u16(io)
  raise "Bad version #{version_major}.#{version_minor}" unless version_major == VERSION_MAJOR and version_minor == VERSION_MINOR
  thiszone = i32(io)     # TODO use it
  sigfigs = u32(io)
  snaplen = u32(io)
  network = u32(io)          # 1 == Ethernet
  header = self.new(network)
  header.sigfigs = sigfigs
  header.snaplen = snaplen
  header
end

Instance Method Details

#write(io) ⇒ Object

io is a stream open for writing TODO good API, name, usage



62
63
64
65
66
67
68
69
70
# File 'lib/pcap/savefile.rb', line 62

def write(io)
  wu32(io, MAGIC_NUMBER)
  wu16(io, VERSION_MAJOR)
  wu16(io, VERSION_MINOR)
  wi32(io, THIS_ZONE)
  wu32(io, sigfigs)
  wu32(io, snaplen)
  wu32(io, network)
end