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

Quick Search    Search Deep

com.voytechs.jnetstream.io
Class PcapInputStream  view PcapInputStream download PcapInputStream.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.PcapInputStream
All Implemented Interfaces:
java.io.Closeable

public class PcapInputStream
extends PacketInputStream

Structure of TCPDump file.
struct pcap_file_header {
bpf_u_int32 magic;
u_short version_major;
u_short version_minor;
bpf_int32 thiszone; // gmt to local correction //
bpf_u_int32 sigfigs; // accuracy of timestamps //
bpf_u_int32 snaplen; // max length saved portion of each pkt //
bpf_u_int32 linktype; // data link type (LINKTYPE_*) //
};


Now per each packet:
struct pcap_pkthdr {
struct timeval ts; // time stamp //
bpf_u_int32 caplen; // length of portion present //
bpf_u_int32 len; // length this packet (off wire) //
};


Field Summary
private static boolean debug
           
private static int PCAP_MAGIC_NUMBER1
           
private static int PCAP_MAGIC_NUMBER2
           
private  int pcapLinktype
           
private  int pcapMagicNumber
           
private  int pcapMajorVer
           
private  int pcapMinorVer
           
private  int pcapPacketCaptureNanos
           
private  long pcapPacketCaptureSecs
           
private  long pcapPacketLength
           
private  long pcapSnaplen
           
private  int pcapTimestampAccuracy
           
private  int pcapTimezone
           
 
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
PcapInputStream(java.io.InputStream pcapFileFormatInputStream)
           
PcapInputStream(java.lang.String filename)
          Opens up the given file and starts processing the data.
 
Method Summary
 int getPcapMagicNumber()
          Returns the magic number found at the beginning of the PCAP file.
 int getPcapMajorVer()
          Returns the major version number of the PCAP file.
 int getPcapMinorVer()
          Returns the minor version number of the PCAP file.
protected  void initPacketStream()
          Since we know we are dealing with a Pcap-file formatted stream (i.e.
static void main(java.lang.String[] args)
          Test function for PcapInputStream
 int pcapLinktype()
          The link type of the first header in the packet.
 int pcapPacketCaptureNanos()
          Number of naono seconds found in the raw data file.
 long pcapPacketCaptureSecs()
          Number of raw number of the capture file.
 long pcapSnaplen()
          Retuns the SNAP len of the capture file.
 int pcapTimestampAccuracy()
          Returns the timestamp accuracy found in the PCAP file.
 int pcapTimezone()
          Returns the timezone found in the PCAP file.
protected  void readPacketPreHeader()
          Read pre-packet header from stream.
 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

PCAP_MAGIC_NUMBER1

private static final int PCAP_MAGIC_NUMBER1
See Also:
Constant Field Values

PCAP_MAGIC_NUMBER2

private static final int PCAP_MAGIC_NUMBER2
See Also:
Constant Field Values

pcapMagicNumber

private int pcapMagicNumber

pcapMajorVer

private int pcapMajorVer

pcapMinorVer

private int pcapMinorVer

pcapTimezone

private int pcapTimezone

pcapTimestampAccuracy

private int pcapTimestampAccuracy

pcapPacketLength

private long pcapPacketLength

pcapSnaplen

private long pcapSnaplen

pcapLinktype

private int pcapLinktype

pcapPacketCaptureSecs

private long pcapPacketCaptureSecs

pcapPacketCaptureNanos

private int pcapPacketCaptureNanos
Constructor Detail

PcapInputStream

public PcapInputStream(java.io.InputStream pcapFileFormatInputStream)
                throws java.io.IOException,
                       EOPacketStream,
                       StreamFormatException

PcapInputStream

public PcapInputStream(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 Pcap-file formatted stream (i.e. FileInputStream("pcap-capturefile.pcap")) we initialize the ProtocolInputStream using values extracted from the pcap stream. First we extract the "pcap_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()).


getPcapMagicNumber

public int getPcapMagicNumber()
Returns the magic number found at the beginning of the PCAP file.


getPcapMajorVer

public int getPcapMajorVer()
Returns the major version number of the PCAP file.


getPcapMinorVer

public int getPcapMinorVer()
Returns the minor version number of the PCAP file.


pcapTimezone

public int pcapTimezone()
Returns the timezone found in the PCAP file. The timezone is used for proper timestamp calculations of the captured packet.


pcapTimestampAccuracy

public int pcapTimestampAccuracy()
Returns the timestamp accuracy found in the PCAP file.


pcapSnaplen

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


pcapLinktype

public int pcapLinktype()
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.


pcapPacketCaptureSecs

public long pcapPacketCaptureSecs()
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.


pcapPacketCaptureNanos

public int pcapPacketCaptureNanos()
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 PcapInputStream