Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.voytechs.jnetstream.io
Class SnoopInputStream  view SnoopInputStream download SnoopInputStream.java

java.lang.Object
  extended byjava.io.InputStream
      extended bycom.voytechs.jnetstream.io.ProtocolDataInputStream
          extended bycom.voytechs.jnetstream.io.PacketInputStream
              extended bycom.voytechs.jnetstream.io.SnoopInputStream
All Implemented Interfaces:
java.io.Closeable

public class SnoopInputStream
extends PacketInputStream

For structure of the Snoop file see RFC1761 http://www.faqs.org/rfcs/rfc1761.html


Field Summary
private static boolean debug
           
private static java.lang.String[] linkNames
           
private static byte[] SNOOP_MAGIC_NUMBER
           
private  long snoopCumulativeDrops
           
private  long snoopLinktype
           
private  byte[] snoopMagicNumber
           
private  long snoopMajorVer
           
private  long snoopPacketCaptureNanos
           
private  long snoopPacketCaptureSecs
           
private  long snoopPacketLength
           
private  long snoopRecordLength
           
private  long snoopSnaplen
           
 
Fields inherited from class com.voytechs.jnetstream.io.PacketInputStream
captureDeviceArch, captureDeviceFilename, captureDeviceIp, captureDeviceOS, captureLive, linkType, packetCaptureTimestamp, packetEnd, packetLength, packetSnaplen, packetStart, recordEnd, recordLength, recordStart, stackIn
 
Fields inherited from class com.voytechs.jnetstream.io.ProtocolDataInputStream
bitsLeft, in
 
Constructor Summary
SnoopInputStream(java.io.InputStream snoopFileFormatInputStream)
           
SnoopInputStream(java.lang.String filename)
          Opens up the given file and starts processing the data.
 
Method Summary
 byte[] getSnoopMagicNumber()
          Returns the magic number found at the beginning of the SNOOP file.
 long getSnoopMajorVer()
          Returns the major version number of the SNOOP file.
protected  void initPacketStream()
          Since we know we are dealing with a Snoop-file formatted stream (i.e.
static void main(java.lang.String[] args)
          Test function for SnoopInputStream
protected  void readPacketPreHeader()
          Read pre-packet header from stream.
 long snoopLinktype()
          The link type of the first header in the packet.
 long snoopPacketCaptureNanos()
          Number of naono seconds found in the raw data file.
 long snoopPacketCaptureSecs()
          Number of raw number of the capture file.
 long snoopSnaplen()
          Retuns the SNAP len of the capture file.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class com.voytechs.jnetstream.io.PacketInputStream
bitsLeft, clear, getCaptureDeviceAddress, getCaptureDeviceArch, getCaptureDeviceFilename, getCaptureDeviceIp, getCaptureDeviceOS, getCaptureTimestamp, getLinkType, getPacketEnd, getPacketLength, getPacketLengthRemaining, getPacketSnaplen, getPacketStart, getRecordEnd, getRecordHeaderLength, getRecordLength, getRecordStart, goToEndOfRecord, gotoMark, hasForceRead, hex, isCaptureLive, isPacketReady, isReady, isReady, nextPacket, pop, position, printStream, push, push, read, setCaptureTimestamp, setForceRead, setLinkType, setPacketLength, setPacketSnaplen, setPacketStart, setRecordLength, setRecordStart, skip
 
Methods inherited from class com.voytechs.jnetstream.io.ProtocolDataInputStream
readBits, readBitsLong, readBoolean, readByte, readFromPacket, readFromPacket, readInt, readIntLittleEndian, readLong, readLongLittleEndian, readShort, readShortLittleEndian, readUnsignedByte, readUnsignedInt, readUnsignedIntLittleEndian, readUnsignedShort, readUnsignedShortLittleEndian, reThrow
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

private static final boolean debug
See Also:
Constant Field Values

SNOOP_MAGIC_NUMBER

private static final byte[] SNOOP_MAGIC_NUMBER

snoopMagicNumber

private byte[] snoopMagicNumber

snoopMajorVer

private long snoopMajorVer

snoopSnaplen

private long snoopSnaplen

snoopLinktype

private long snoopLinktype

snoopPacketCaptureSecs

private long snoopPacketCaptureSecs

snoopPacketCaptureNanos

private long snoopPacketCaptureNanos

snoopPacketLength

private long snoopPacketLength

snoopRecordLength

private long snoopRecordLength

snoopCumulativeDrops

private long snoopCumulativeDrops

linkNames

private static java.lang.String[] linkNames
Constructor Detail

SnoopInputStream

public SnoopInputStream(java.io.InputStream snoopFileFormatInputStream)
                 throws java.io.IOException,
                        EOPacketStream,
                        StreamFormatException

SnoopInputStream

public SnoopInputStream(java.lang.String filename)
                 throws java.io.FileNotFoundException,
                        java.io.IOException,
                        EOPacketStream,
                        StreamFormatException
Opens up the given file and starts processing the data.

Method Detail

initPacketStream

protected void initPacketStream()
                         throws java.io.IOException,
                                EOPacketStream,
                                StreamFormatException
Since we know we are dealing with a Snoop-file formatted stream (i.e. FileInputStream("snoop-capturefile.snoop")) we initialize the ProtocolInputStream using values extracted from the snoop stream. First we extract the "snoop_file_heaer" as specified above.

Overrides:
initPacketStream in class PacketInputStream

readPacketPreHeader

protected void readPacketPreHeader()
                            throws java.io.IOException,
                                   EOPacketStream,
                                   StreamFormatException
Read pre-packet header from stream. With basic info about the next packet to follow. this is called for every packet in the stream. Main purpose is to get packet-data length (or length of captured packet) and the capture time of the packet.

Overrides:
readPacketPreHeader in class PacketInputStream

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


getSnoopMagicNumber

public byte[] getSnoopMagicNumber()
Returns the magic number found at the beginning of the SNOOP file.


getSnoopMajorVer

public long getSnoopMajorVer()
Returns the major version number of the SNOOP file.


snoopSnaplen

public long snoopSnaplen()
Retuns the SNAP len of the capture file. This is the number of bytes that we saved, not captured. i.e. first 128 bytes.


snoopLinktype

public long snoopLinktype()
The link type of the first header in the packet. Normally this is type 2 (ethernet) but any of the others are possible as well.


snoopPacketCaptureSecs

public long snoopPacketCaptureSecs()
Number of raw number of the capture file. JNetStream library multiplies this number by factor of 1000 before returning it.

This value changes from packet to packet.


snoopPacketCaptureNanos

public long snoopPacketCaptureNanos()
Number of naono seconds found in the raw data file. This number is also multiplied by 1000.

This value changes from packet to packet.


main

public static void main(java.lang.String[] args)
Test function for SnoopInputStream