SourceForge Jpcap

net.sourceforge.jpcap.net
Class PacketFactory

java.lang.Object
  extended by net.sourceforge.jpcap.net.PacketFactory
Direct Known Subclasses:
LLC.PacketFactory, SNAP.PacketFactory

public class PacketFactory
extends Object

This factory constructs high-level packet objects from captured data streams. The createUnknownPacket(int, java.nio.ByteBuffer, net.sourceforge.jpcap.util.Timeval) method can be overridden to allow applications to provide custom Packet classes for protocols of local interest.

In addition, the PacketFactories.properties file can be over-ridden to add additional PacketFactory implementations for new protocols. See the PacketFactories.properties file provided for details. This file is loaded from whichever of jpcap.jar or jpcap-core.jar you are using, but:

Version:
$Revision: 1.1 $
Author:
Patrick Charles and Jonas Lehmann, Esmond Pitt
Last modified by:
$Author: esmondpitt $
Last modified at:
$Date: 2008/08/21 02:58:28 $

Field Summary
protected static Map<String,Constructor<? extends Packet>> classes
           
static String ETHERNET8023_PREFIX
           
static String ETHERNETII_PREFIX
          .properties file key prefixes.
protected static Map<String,Method> factories
           
static String FACTORY_METHOD_NAME
           
static String PACKET_FACTORY_PROPERTIES
          Name of the .properties file.
protected static Properties properties
           
 
Constructor Summary
PacketFactory()
           
 
Method Summary
protected  Packet createPacket(int linkType, ByteBuffer bb, Timeval tv)
          Returns a Packet object for the specified linkType and data.
protected static Packet createPacket(String key, int lLen, ByteBuffer bb, Timeval tv)
          Create a packet given a properties-file key.
protected  Packet createUnknownPacket(int lLen, ByteBuffer bb, Timeval tv)
          Return a Packet object for an unknown packet format.
static Packet dataToPacket(int linkType, byte[] bytes)
          Convert captured packet data into an object.
static Packet dataToPacket(int linkType, byte[] bytes, Timeval tv)
          Convert captured packet data into an object.
static Packet dataToPacket(int linkType, ByteBuffer bb, Timeval tv)
          Convert captured packet data into an object.
static PacketFactory getInstance()
          Get the installed PacketFactory instance.
static void setDefault(PacketFactory defaultFactory)
          Set the default packet factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKET_FACTORY_PROPERTIES

public static final String PACKET_FACTORY_PROPERTIES
Name of the .properties file.

Since:
2.0.0
See Also:
Constant Field Values

ETHERNETII_PREFIX

public static final String ETHERNETII_PREFIX
.properties file key prefixes.

Since:
2.0.0
See Also:
Constant Field Values

ETHERNET8023_PREFIX

public static final String ETHERNET8023_PREFIX
See Also:
Constant Field Values

FACTORY_METHOD_NAME

public static final String FACTORY_METHOD_NAME
See Also:
Constant Field Values

properties

protected static Properties properties

factories

protected static Map<String,Method> factories

classes

protected static Map<String,Constructor<? extends Packet>> classes
Constructor Detail

PacketFactory

public PacketFactory()
Method Detail

setDefault

public static void setDefault(PacketFactory defaultFactory)
Set the default packet factory.

Parameters:
defaultFactory - PacketFactory object for unrecognized packets
Since:
2.0.0

dataToPacket

public static Packet dataToPacket(int linkType,
                                  byte[] bytes)
Convert captured packet data into an object.

Parameters:
linkType - Link type
bytes - Packet data
Returns:
a Packet object

dataToPacket

public static Packet dataToPacket(int linkType,
                                  byte[] bytes,
                                  Timeval tv)
Convert captured packet data into an object.

Parameters:
linkType - Link type
bytes - Packet data
tv - Timeval
Returns:
a Packet object

dataToPacket

public static Packet dataToPacket(int linkType,
                                  ByteBuffer bb,
                                  Timeval tv)
Convert captured packet data into an object.

Parameters:
linkType - Link type
bb - Packet data in a ByteBuffer
tv - Timeval
Returns:
a Packet object
Since:
2.0.0

getInstance

public static PacketFactory getInstance()
Get the installed PacketFactory instance. If no default has been set, reutrns an instance of this class.

Returns:
a PacketFactory instance.
Since:
2.0.0

createPacket

protected final Packet createPacket(int linkType,
                                    ByteBuffer bb,
                                    Timeval tv)
Returns a Packet object for the specified linkType and data. Calls createUnknownPacket(int, java.nio.ByteBuffer, net.sourceforge.jpcap.util.Timeval) for a packet which isn't recognized by this method; if that returns null, returns an EthernetPacket.

Supported packet types include:

Parameters:
linkType - Link type
bb - ByteBuffer
tv - Timeval, or null
Returns:
a Packet corresponding to the data received.
Since:
2.0.0

createUnknownPacket

protected Packet createUnknownPacket(int lLen,
                                     ByteBuffer bb,
                                     Timeval tv)
Return a Packet object for an unknown packet format. This implementation returns null. Derived classes may override, to recognize protocols of local interest.

Parameters:
lLen - Length of link-layer header data to ignore
bb - Packet data in a ByteBuffer
tv - Timeval, or null
Returns:
a Packet, or null.
Since:
2.0.0

createPacket

protected static Packet createPacket(String key,
                                     int lLen,
                                     ByteBuffer bb,
                                     Timeval tv)
Create a packet given a properties-file key.

Parameters:
key - Properties-file key, e.g. Ethernet802.3Protocol.dsapssap.0xaaaa.org.0x000c.protocol.0x2000
lLen - Link-layer l=header length
bb - Packet data in a ByteBuffer
tv - Timeval of packet
Returns:
a Packet, or null.

Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008.