jnetpcap.capture.file
Interface BlockRecord

All Superinterfaces:
Record
All Known Subinterfaces:
MutableBlockRecord, NAPBlock, PcapBlockRecord, SnoopBlockRecord

public interface BlockRecord
extends Record

A block record also sometimes refered to a file header in a capture file which uniquely identifies the file as certain type with a magic pattern or magic number. Block record contains, as children, one or more data records which usually contain packet data.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from interface jnetpcap.capture.file.Record
Record.Capability, Record.RecordType
 
Method Summary
 java.nio.ByteOrder getByteOrder()
           
 byte[] getMagicPattern()
          Returns the Magic number or pattern that is used to uniquely identify the file type of the capture file.
 long getPacketCount()
          Returns the number of packets within the file.
 long getPacketCount(PacketCounterModel model)
          Gets the packet count using a different algorithm.
<E extends DataRecord>
RecordIterator<E>
getRecords(java.lang.Class<E> c)
           
 Version getVersion()
          Returns the first file version found.
 void setVersion(int major, int minor)
           
 void setVersion(Version version)
           
 
Methods inherited from interface jnetpcap.capture.file.Record
getCaptureFile, getFilePosition, getHeaderBuffer, getHeaderLength, getRecordLength, getRecordType, isModified, isWritten, read, readHeader, setFilePosition, setModified, setWritten, validateRecord, write, writeHeader
 

Method Detail

getByteOrder

java.nio.ByteOrder getByteOrder()

getPacketCount

long getPacketCount()
                    throws java.io.IOException

Returns the number of packets within the file. This only includes records that hold packet data and not any additional meta data records. The method uses the default PacketCounter. If estimated packet counter is acceptable you can use one of of several other PacketCounterModels to calculate estimated packet count using the getPacketCount(PacketCounterModel) method.

The default PacketCounterModel is file type specific. The model at minimum returns an accurate count of packet records within the capture file, but no guarrantees about performance can be made and the performance will vary from format to format. You can use the more explicit getPacketCount(PacketCounterModel) method to counter packets.

Returns:
total number of packets within the file using the default model
Throws:
java.io.IOException - any io errors

getPacketCount

long getPacketCount(PacketCounterModel model)
                    throws java.io.IOException
Gets the packet count using a different algorithm. There are several different types of algorithms or PacketCounterModels to choose from, each has its own benefits and drawback. The reason that multiple algorithms are provided is that counting packets in a capture file can be extremely time consuming in large capture files since most capture files (with the exception of NAP) do not provide any sort of packet indexing or maintain a global count of packets within the entire file. Therefore the packets have to be in most cases iterated and counted. One of the models allows a statistical calculation upon the file which does not return a true packet count but is very close to the real number and in certain situations may be good enough.

Parameters:
model - model/algorithm to use to count packets
Returns:
number of packets calculated by the model
Throws:
java.io.IOException - any io exceptions

getVersion

Version getVersion()
Returns the first file version found. There may be multiple blocks within the file at different versions.

Returns:
version of the file

setVersion

void setVersion(int major,
                int minor)
                throws java.io.IOException
Throws:
java.io.IOException

setVersion

void setVersion(Version version)
                throws java.io.IOException
Throws:
java.io.IOException

getRecords

<E extends DataRecord> RecordIterator<E> getRecords(java.lang.Class<E> c)
                                                throws java.io.IOException,
                                                       CaptureFormatException
Throws:
java.io.IOException
CaptureFormatException

getMagicPattern

byte[] getMagicPattern()
                       throws java.io.IOException
Returns the Magic number or pattern that is used to uniquely identify the file type of the capture file. The magic number is not normalized so the pattern may be returned differently on big and small endian machines.

Returns:
pattern that is used to identify the file type
Throws:
java.io.IOException - any IO errors