jnetpcap.capture
Interface CaptureFactory.Factory

All Known Subinterfaces:
CaptureFactory.LocalFactory, CaptureFactory.RemoteFactory, RemoteSession
Enclosing class:
CaptureFactory

public static interface CaptureFactory.Factory

An Abstract Factory pattern which creates concrete capture objects.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Method Summary
 void append(Capture source, FileCapture destination)
          Copies all of the CapturePackets returned by the source into the already open capture file.
 void catFile(java.io.File dst, Capture... srcs)
          Concatenate all the files into the
 void catFile(java.io.File dst, java.io.File... srcs)
          Concatenate all the files into the
 boolean compactFile(java.io.File file)
          Cleans up and compacts the file contents to most efficient size and layout.
 void convertFile(java.io.File source, java.io.File destination, FileType destinationType)
          Converts the source file into new file with the destinationType file format.
 java.util.List<MutableCaptureInterface> listInterfaces()
          Gets a list of all the devices capable of doing live capture on this or remote system.
 MutableFileCapture newFile(java.io.File file, FileType type)
          Creates a new empty file of the user specified type.
 MutableFileCapture newFile(java.io.File file, SuppliedFileTypes type, Capture capture)
          Creates a new file and dumps all of the packet from capture to the new file in the proper format.
 MutableFileCapture newFile(java.io.File file, SuppliedFileTypes type, Version version, java.nio.ByteOrder encoding)
          Creates a new file in the specified format and of the specified version and using the specified byte ordering for all block and data record headers.
 MutableCaptureInterface newInterface()
          Creates a new empty, uninitialized CaptureInterface instance.
 MutableCaptureInterface newInterface(java.net.NetworkInterface netint)
          Creates a new instance of a CaptureInterface initialized from a java.net.NetworkInterface object.
 MutableFileCapture openFile(java.io.File file)
          Gets a mutable FileCapture instance for the specified file.
 MutableFileCapture openFile(java.io.File file, Filter filter)
          Gets a mutable FileCapture instance for the specified file.
 LiveCapture openLive()
          Opens up all interfaces, except loopback and dialup interfaces, for live capture.
 LiveCapture openLive(Filter fiter)
          Opens up all interfaces, except loopback and dialup interfaces, for live capture.
 LiveCapture openLive(Filter filter, CaptureInterface... nics)
           
 LiveCapture openLive(Filter filter, java.util.Collection<CaptureInterface> nics)
           
 java.util.List<java.io.File> splitFile(java.io.File file)
          Splits the file into smaller files according to default rules defined for each file format.
 java.util.List<java.io.File> splitFile(java.io.File file, long packetCount, boolean maxCompression)
          Split the specified file into smaller files containing specified number of packets each from the source file.
 FileType typeOfFile(java.io.File file)
          Determines the file type of the supplied file.
 boolean validateFile(java.io.File file)
          Checks if the specified file is in a proper format 100% compabile with specification.
 

Method Detail

append

void append(Capture source,
            FileCapture destination)
            throws java.io.IOException
Copies all of the CapturePackets returned by the source into the already open capture file.

Parameters:
source - capture source to read packets from
destination - capture file to write the packets into
Throws:
java.io.IOException - any IO errors

catFile

void catFile(java.io.File dst,
             java.io.File... srcs)
             throws java.io.FileNotFoundException,
                    java.io.IOException
Concatenate all the files into the

Parameters:
dst - file to store all the concatenated data
srcs - array of source files to concatenate together
Throws:
java.io.IOException
java.io.FileNotFoundException

catFile

void catFile(java.io.File dst,
             Capture... srcs)
Concatenate all the files into the

Parameters:
dst - file to store all the concatenated data
srcs - array of source files to concatenate together

compactFile

boolean compactFile(java.io.File file)
Cleans up and compacts the file contents to most efficient size and layout.

Parameters:
file - file to compact
Returns:
true if successfull, otherwise false

convertFile

void convertFile(java.io.File source,
                 java.io.File destination,
                 FileType destinationType)
                 throws java.io.IOException
Converts the source file into new file with the destinationType file format. You can convert any supported file type into any other supported file type including different versions of the same file format.

Parameters:
source - source file to do conversion on
destination - will create a new destination file in the destinationType format
destinationType - the format that new destination file will be created
Throws:
java.io.IOException - any IO errors

newFile

MutableFileCapture newFile(java.io.File file,
                           FileType type)
                           throws java.io.IOException
Creates a new empty file of the user specified type.

Parameters:
file - file to create
type - type of file to create
Returns:
mutable instance of the empty file just created
Throws:
java.io.IOException - any IO errors

newFile

MutableFileCapture newFile(java.io.File file,
                           SuppliedFileTypes type,
                           Capture capture)
                           throws java.io.IOException
Creates a new file and dumps all of the packet from capture to the new file in the proper format.

Parameters:
file - file to create
type - the type of file to create
capture - source of CapturePackets which will be dumped into the new file
Returns:
open instance of this new file
Throws:
java.io.IOException - any IO errors

newFile

MutableFileCapture newFile(java.io.File file,
                           SuppliedFileTypes type,
                           Version version,
                           java.nio.ByteOrder encoding)
                           throws java.io.IOException
Creates a new file in the specified format and of the specified version and using the specified byte ordering for all block and data record headers. If the byte order specified is not supported by the format appropriate IOException will be thrown with an error.

Parameters:
file - file to create
type - type of file to create
version - version of the file to create
encoding - byte order of all integer values in the block record (file header) or data record (file records) headers.
Returns:
Mutable instance of FileCapture with which you can add packets to the file
Throws:
java.io.IOException - any IO errors

openFile

MutableFileCapture openFile(java.io.File file)
                            throws java.io.IOException
Gets a mutable FileCapture instance for the specified file. The MutableFileCapture is ready to read or modify records within the specified file.

Parameters:
file - filename to open for reading and writting
Returns:
Mutable instance of FileCapture
Throws:
java.io.IOException - any IO or format errors

openFile

MutableFileCapture openFile(java.io.File file,
                            Filter filter)
                            throws java.io.IOException
Gets a mutable FileCapture instance for the specified file. The MutableFileCapture is ready to read or modify records within the specified file. The supplied filter is applied to packet record data and only records matching the filter are returned by the MutableFileCapture instance.

Parameters:
file - filename to open for reading and writting
Returns:
Mutable instance of FileCapture
Throws:
java.io.IOException - any IO or format errors

openLive

LiveCapture openLive()
                     throws java.io.IOException
Opens up all interfaces, except loopback and dialup interfaces, for live capture. The captured packets can be iterated over using the inherited methods IOIterator#hasNext and IOIterator#next. There is no guarrantee as to the order in which captured packets are returned between multiple interfaces, with the exception that for each interface the packets will be returned in the order they were captured on that interface.

Returns:
a capture capturing packets on all interfaces, with the above specified exceptions
Throws:
java.io.IOException - any IO errors

openLive

LiveCapture openLive(Filter fiter)
                     throws java.io.IOException

Opens up all interfaces, except loopback and dialup interfaces, for live capture. The captured packets can be iterated over using the inherited methods IOIterator#hasNext and IOIterator#next. There is no guarrantee as to the order in which captured packets are returned between multiple interfaces, with the exception that for each interface the packets will be returned in the order they were captured on that interface.

The filter is used to limit the number of packets captured to ones that match the filter criteria. Each packet after capture is matched by the filter. For efficiency this is done at the kernel level for operating systems that support this feature. On operating systems that do not, the filter match is performed in "userland" or user space which is less efficient

Parameters:
fiter -
Returns:
Throws:
java.io.IOException

openLive

LiveCapture openLive(Filter filter,
                     java.util.Collection<CaptureInterface> nics)
                     throws java.io.IOException
Throws:
java.io.IOException

openLive

LiveCapture openLive(Filter filter,
                     CaptureInterface... nics)
                     throws java.io.IOException
Throws:
java.io.IOException

splitFile

java.util.List<java.io.File> splitFile(java.io.File file)
                                       throws java.io.IOException

Splits the file into smaller files according to default rules defined for each file format. For NAP the file will be split with each Block Record being split into its own seperate file. For other files, the defaults are to split the files into byte files.

The base filename supplied is used as the base filename for all newly created files with the -XXXX appended to them.

The source file is unmodified

Parameters:
file - file to be split
Returns:
list of newly created files
Throws:
java.io.IOException

splitFile

java.util.List<java.io.File> splitFile(java.io.File file,
                                       long packetCount,
                                       boolean maxCompression)
                                       throws java.io.IOException

Split the specified file into smaller files containing specified number of packets each from the source file. New files are created to hold only the specified number of packets and associated meta records. The supplied filename is used as a base filename for all newly created files with the post fix of -XXXX appended to them.

The source file is unmodified

Parameters:
file - source file to split
packetCount - split using this many packets from the source file copied into the newly created files
maxCompression - true means produce the smallest possible file, while false means leave it upto the default algorithm for each spcific file type. For example NAP files pad their files to 512Kb by default which means that files containing even only a single packet are of minimum size 512 Kb, but this can be overriden by setting maxCompression to true. Notice that it will be harder to split the NAP file with regular unix commands if default padding is not used.
Returns:
list of all the new files created
Throws:
java.io.IOException

typeOfFile

FileType typeOfFile(java.io.File file)
                    throws java.io.IOException
Determines the file type of the supplied file. This similar method to the dynamic counter part CaptureFile.getType(), but does not require the file to be opened before hand and is quicker then using CaptureFile.openFile().getType() sequence. As more specific algorithm is used.

Parameters:
file - file to check and return file type
Returns:
file type of the supplied file or null if file type unknown or not supported
Throws:
java.io.IOException

validateFile

boolean validateFile(java.io.File file)
                     throws java.io.IOException
Checks if the specified file is in a proper format 100% compabile with specification.

Parameters:
file - file to validate
Returns:
true if file is valid with the specification, otherwise false, even if minor infringements are found
Throws:
java.io.IOException

newInterface

MutableCaptureInterface newInterface()
Creates a new empty, uninitialized CaptureInterface instance. You must use its set methods to set all the properties yourself.

Returns:
empty instance of a capture device

newInterface

MutableCaptureInterface newInterface(java.net.NetworkInterface netint)
                                     throws java.io.IOException
Creates a new instance of a CaptureInterface initialized from a java.net.NetworkInterface object. The object is primarily initialized from the NetworkInterface object data, but several other sources provide some of the property information as well, such as java system properties and possibly low level, JNI based queries as well.

Parameters:
netint - network interface object to initialize from
Returns:
new instance of CaptureInterface
Throws:
java.io.IOException

listInterfaces

java.util.List<MutableCaptureInterface> listInterfaces()
                                                       throws java.io.IOException
Gets a list of all the devices capable of doing live capture on this or remote system.

Returns:
list of capture capable devices
Throws:
java.io.IOException - any IO errors