Class: PcapSimple::PcapFile
- Inherits:
-
Object
- Object
- PcapSimple::PcapFile
- Includes:
- Enumerable
- Defined in:
- lib/pcap_simple.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(*args) ⇒ PcapFile
constructor
A new instance of PcapFile.
Constructor Details
#initialize(*args) ⇒ PcapFile
Returns a new instance of PcapFile.
16 17 18 19 20 21 |
# File 'lib/pcap_simple.rb', line 16 def initialize(*args) Hash[*args].each {|k,v| self.send("%s="%k,v)} raise ArgumentError, "need to specify file_name" if file_name.nil? @file=File.open(file_name,"r") @header=PcapHeader.new(file.read(PCAP_HEADER_LEN)) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
14 15 16 |
# File 'lib/pcap_simple.rb', line 14 def file @file end |
#file_name ⇒ Object
Returns the value of attribute file_name.
13 14 15 |
# File 'lib/pcap_simple.rb', line 13 def file_name @file_name end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
14 15 16 |
# File 'lib/pcap_simple.rb', line 14 def header @header end |
Instance Method Details
#each(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pcap_simple.rb', line 22 def each(&block) file.seek(PCAP_HEADER_LEN) loop do header_data=file.read(PACKET_HEADER_LEN) break if (header_data.nil? || header_data.length < PACKET_HEADER_LEN) header=PcapRecord.new(header_data) raw=file.read(header.incl_len) break if (raw.nil? || raw.length < header.incl_len) packet=Packet.new(:raw_data=>raw,:header=>header) yield packet unless packet.datagram.nil? end end |