|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjnetpcap.capture.CaptureFactory
public final class CaptureFactory
Static factory methods for creating and accessing capture sessions. This
class provides a number of static methods for manipulating capture files such
as concatenating multiple files into one, or reverse and splitting a single
large file into multiple smaller ones. Easily get the capture file type or
validate its contents. The most imporant methods though are newFile(java.io.File, jnetpcap.capture.file.SuppliedFileTypes),
openFile(java.io.File) and openLive() which create new blank capture files,
open existing capture file or open network interfaces for live network packet
capture where packets are received directly from the network and passed to the
user.
| Nested Class Summary | |
|---|---|
static interface |
CaptureFactory.Factory
An Abstract Factory pattern which creates concrete capture objects. |
static interface |
CaptureFactory.LocalFactory
Factory interface for local sessions. |
static interface |
CaptureFactory.RemoteFactory
Factory interface for remote sessions. |
| Method Summary | |
|---|---|
static void |
append(MutableCapture destination,
Capture... sources)
Copies all of the CapturePackets returned by the sources into the already open capture file. |
static void |
catFile(java.io.File file,
Capture... sources)
Copies all of the CapturePackets returned by the source a destination capture file. |
static void |
catFile(java.io.File dst,
java.io.File... src)
Concatenate all the files into single dst file |
static boolean |
compactFile(java.io.File file)
Cleans up and compacts the file contents to most efficient size and layout. |
static void |
convertFile(java.io.File source,
java.io.File destination,
FileType destinationType)
Converts the source file into new file with the destinationType file format. |
static CaptureFactory.LocalFactory |
getLocal()
Returns an instance of the current local capture factory which is responsible for creating local capture instances. |
static java.util.List<MutableCaptureInterface> |
listInterfaces()
|
static FileCapture |
newFile(java.io.File file,
SuppliedFileTypes type)
Creates a new file of the request type |
static FileCapture |
newFile(java.io.File file,
SuppliedFileTypes type,
Capture capture)
A convenience utility method which creates a new file and dumps all of the packet from capture to the new file in the proper format. |
static FileCapture |
newFile(java.io.File file,
SuppliedFileTypes type,
Version version,
java.nio.ByteOrder encoding)
Creates a new file in the specified format, specified version and using the specified byte encoding. |
static MutableFileCapture |
openFile(java.io.File file)
Opens a file for reading and writting. |
static MutableFileCapture |
openFile(java.io.File file,
Filter filter)
Opens a file for reading and writting while applying a filter to limit what is returned. |
static FileCapture |
openFile(java.io.InputStream in)
Uses an InputStream for reading in a capture. |
static LiveCapture |
openLive()
Opens up a network interfaces for live packet capture. |
static LiveCapture |
openLive(CaptureInterface nic)
Opens up a network interface for live packet capture. |
static LiveCapture |
openLive(java.util.Collection<CaptureInterface> nics)
Opens up a network interfaces for live packet capture. |
static LiveCapture |
openLive(Filter filter,
CaptureInterface nic)
Opens up a network interface for live packet capture with a filter. |
static LiveCapture |
openLive(Filter filter,
java.util.Collection<CaptureInterface> nics)
Opens up a network interfaces for live packet capture with a filter. |
static void |
setLocalCaptureFactory(CaptureFactory.LocalFactory local)
Allows complete override of the implementation of Capture Framework. |
static 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. |
static 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. |
static FileType |
typeOfFile(java.io.File file)
Determines the file type of the supplied file. |
static FileType |
typeOfFile(java.io.InputStream fileStream)
Determines the file type of the supplied stream. |
static boolean |
validateFile(java.io.File file)
Checks if the specified file is in a proper format 100% compabile with specification. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void append(MutableCapture destination,
Capture... sources)
throws java.io.IOException
sources - capture sources to read packets fromdestination - mutable capture to write the packets into
java.io.IOException - any IO errors
public static void catFile(java.io.File file,
Capture... sources)
throws java.io.IOException
sources - capture sources to read packets fromfile - destination file to write the packets into
java.io.IOException - any IO errors
public static void catFile(java.io.File dst,
java.io.File... src)
throws java.io.FileNotFoundException,
java.io.IOException
dst - destination file to concatenate the src files tosrc - array of source files to concatenate contents from
java.io.IOException
java.io.FileNotFoundExceptionpublic static boolean compactFile(java.io.File file)
file - file to compact
public static void convertFile(java.io.File source,
java.io.File destination,
FileType destinationType)
throws java.io.IOException
source - source file to do conversion ondestination - will create a new destination file in the destinationType formatdestinationType - the format that new destination file will be created
java.io.IOException - any IO errorspublic static CaptureFactory.LocalFactory getLocal()
Returns an instance of the current local capture factory which
is responsible for creating local capture instances. This is synonymous
with the RemoteSession counter part which extends the RemoteFactory interface.
The methods between Factory, LocalFactory and RemoteFactory
are partitioned in a such a way to only allow operations that make sense with the given
interface. For example, the RemoteLocalFactory interface does not contain any of the
methods that LocalFactory does to open a live network capture using standard
java.net.NetworkInterface objects. This is because NetworkInterface objects don't make
sense on client machine, they are only instantiated by runtime environment for local machines.
Therefore you need to use one of the methods that are allowed for remote capture such as
openLive(CaptureInterface) method where CaptureInterface is this frameworks
concept and is allowed to be shared accross multiple machines.
public static void setLocalCaptureFactory(CaptureFactory.LocalFactory local)
local - new local factory for all capture framework's operations
public static FileCapture newFile(java.io.File file,
SuppliedFileTypes type)
throws java.io.IOException
file - type -
java.io.IOException
public static FileCapture newFile(java.io.File file,
SuppliedFileTypes type,
Capture capture)
throws java.io.IOException
file - file to createtype - the type of file to createcapture - source of CapturePackets which will be dumped into the new file
java.io.IOException - any IO errors
public static FileCapture newFile(java.io.File file,
SuppliedFileTypes type,
Version version,
java.nio.ByteOrder encoding)
throws java.io.IOException
file - type - version - encoding -
java.io.IOException
public static MutableFileCapture openFile(java.io.File file)
throws java.io.IOException
file -
java.io.IOException
public static MutableFileCapture openFile(java.io.File file,
Filter filter)
throws java.io.IOException
file - filter -
java.io.IOException
public static FileCapture openFile(java.io.InputStream in)
throws java.io.IOException
FileInputStream filestream = new FileInputStream("somefile.pcap");
FileCapture capture = CaptureFactory.openFile(filestream);
capture.close();
It is expected that the format of the stream as the same as in the physical file.
This method is useful in situations if a file must be decompressed or decrypted
using a stream. The only difference between this version of openFile and others that
open the file directly is that no mutable or seekable operations are permitted on
stream based files. Since InputStream is readonly object. Also think if you have a
huge capture file on disk in compressed format, if all that is needed is to decompress
the file content on the fly for read-only access, this method is perfect. Otherwise you
can decompress this huge file potentially huge file on the disk and then open it
for mutable operations.
in - input stream to read the capture contents in supported file format from
java.io.IOException - any IO errors
public static LiveCapture openLive()
throws java.io.IOException
java.io.IOException - any IO errors
public static LiveCapture openLive(java.util.Collection<CaptureInterface> nics)
throws java.io.IOException
Opens up a network interfaces for live packet capture. The specified network interfaces are opened for capture with including loopback interface if specified. LiveCapture extends the Capture interface which provides simple iterator through which all the captured packets are returned one after the other. There is no guarrantee as to the order in which packets are returned when more then one interface is used for packet capture at the same time. Its simply left upto the underlying implementation to determine the order. Each CapturePacket maintains a reference to a CaptureInterface which is associated with the interface that captured the particular packet.
nics - collection of network interfaces to open, including loopbacks if part of the collection
java.io.IOException - any IO errors
public static LiveCapture openLive(Filter filter,
java.util.Collection<CaptureInterface> nics)
throws java.io.IOException
Opens up a network interfaces for live packet capture with a filter. The specified network interfaces are opened for capture with including loopback interface if specified. LiveCapture extends the Capture interface which provides simple iterator through which all the captured packets are returned one after the other. There is no guarrantee as to the order in which packets are returned when more then one interface is used for packet capture at the same time. Its simply left upto the underlying implementation to determine the order. Each CapturePacket maintains a reference to a CaptureInterface which is associated with the interface that captured the particular packet.
Filter is applied directly by the kernel, this feature is operating system dependent, to efficiently accept or reject packets as close to the hardware level as possible with no extraneous in memory copies. Most modern operating system support this feature. If this feature is not available the filter is applied in "userland" or in user space which is less efficient.
nics - filter -
java.io.IOException
public static LiveCapture openLive(CaptureInterface nic)
throws java.io.IOException
Opens up a network interface for live packet capture. The specified network interface will be opened for live network packet capture. LiveCapture extends the Capture interface which provides simple iterator through which all the captured packets are returned one after the other. There is no guarrantee as to the order in which packets are returned when more then one interface is used for packet capture at the same time. Its simply left upto the underlying implementation to determine the order. Each CapturePacket maintains a reference to a CaptureInterface which is associated with the interface that captured the particular packet.
nic -
java.io.IOException
public static LiveCapture openLive(Filter filter,
CaptureInterface nic)
throws java.io.IOException
Opens up a network interface for live packet capture with a filter. The specified network interface will be opened for live network packet capture. LiveCapture extends the Capture interface which provides simple iterator through which all the captured packets are returned one after the other. There is no guarrantee as to the order in which packets are returned when more then one interface is used for packet capture at the same time. Its simply left upto the underlying implementation to determine the order. Each CapturePacket maintains a reference to a CaptureInterface which is associated with the interface that captured the particular packet.
Filter is applied directly by the kernel, this feature is operating system dependent, to efficiently accept or reject packets as close to the hardware level as possible with no extraneous in memory copies. Most modern operating system support this feature. If this feature is not available the filter is applied in "userland" or in user space which is less efficient.
nic - filter -
java.io.IOException
public static 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
file - file to be split
java.io.IOException
public static 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
file - source file to splitpacketCount - split using this many packets from the source file copied into the newly created filesmaxCompression - 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.
java.io.IOException
public static FileType typeOfFile(java.io.File file)
throws java.io.IOException
file - file to check and return file type
java.io.IOException
public static FileType typeOfFile(java.io.InputStream fileStream)
throws java.io.IOException
file - file to check and return file type
java.io.IOException
public static boolean validateFile(java.io.File file)
throws java.io.IOException
file - file to validate
java.io.IOException
public static java.util.List<MutableCaptureInterface> listInterfaces()
throws java.io.IOException
java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||