org.jnetpcap.packet
Class JHeaderScanner

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JFunction
          extended by org.jnetpcap.packet.JHeaderScanner

public class JHeaderScanner
extends JFunction

A header scanner, there is one per header, that is able to scan raw memory buffer and determine the length of the header and the next header ID after examining the current header's structure. The header scanner is bound to the native direct scanner provided by the jNetPcap native implementation. The header scanner can be overriden with a java implementation by simply subclassing it and overriding the getHeaderLength and getNextHeader methods. If either of the 2 types of methods are overriden, then the user should also overriden the isDirect() method and return false to indicate that this is not a native direct scanner.

The header scanner is natively peered directly with the appropriate function that performs the scan and determines the next protocol in chain of headers found in the data buffer. Another words this class is peered using a function pointer and dispatched appropriately when invoked to scan for length or next header id.

Here is a typedef definition and the function pointer signature.

 typedef void (*native_protocol_func_t)(scan_t *scan);
 
Note that scan_t structure is implemented by java class JScan which is peered with that structure.

Author:
Mark Bednarczyk, Sly Technologies, Inc.
See Also:
JScan

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory
JMemory.Type
 
Field Summary
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME
 
Constructor Summary
JHeaderScanner(java.lang.Class<? extends JHeader> c)
           
JHeaderScanner(JProtocol protocol)
          A java scanner for headers out of a native packet buffer.
 
Method Summary
 boolean addBindings(JBinding... bindings)
           
 void clearBindings()
           
 JBinding[] getBindings()
           
 int getHeaderLength(JPacket packet, int offset)
          Returns the length of the header this scanner is registered for
 int getId()
          Gets the protocol header's numerical ID as assigned by JRegistry
 boolean hasBindings()
           
 boolean hasScanMethod()
           
 boolean isDirect()
          Checks if the scanner at the given ID is a direct or java scanner.
 boolean removeBindings(JBinding... bindings)
           
 int scanAllBindings(JPacket packet, int offset)
          Calculates the next header in sequence of headers within the packet buffer
protected  void scanHeader(JScan scan)
          The main method that this header scanner is called on by the packet scanner, typically from native user space
 void setScannerMethod(AnnotatedScannerMethod method)
           
 java.lang.String toString()
           
 
Methods inherited from class org.jnetpcap.nio.JFunction
getName
 
Methods inherited from class org.jnetpcap.nio.JMemory
check, cleanup, finalize, isInitialized, isJMemoryBasedOwner, isOwner, peer, peer, peer, setSize, size, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JHeaderScanner

public JHeaderScanner(java.lang.Class<? extends JHeader> c)

JHeaderScanner

public JHeaderScanner(JProtocol protocol)
A java scanner for headers out of a native packet buffer. This constructor allows a custom header scanner to be implemented and registered with JRegistry. The packet scanner, JScanner, uses builtin native scanners to scan packet buffers but also allows custom java scanners to override or provide additional header scanners. Any new protocol header being added to jNetPcap library of protocols, that is not officially released with this API, will have to provide its own custom header scanner.

Parameters:
protocol - core protocol constant for which to override its default native header scanner
Method Detail

addBindings

public boolean addBindings(JBinding... bindings)

clearBindings

public void clearBindings()

hasBindings

public boolean hasBindings()

getBindings

public JBinding[] getBindings()
Returns:

getHeaderLength

public int getHeaderLength(JPacket packet,
                           int offset)
Returns the length of the header this scanner is registered for

Parameters:
packet - the packet object this header is bound to
offset - offset into the packet buffer in bytes of the start of this header
Returns:
length of the header or 0 if this header is not found in the packet buffer

getId

public final int getId()
Gets the protocol header's numerical ID as assigned by JRegistry

Returns:
the id numerical ID of the header

isDirect

public boolean isDirect()
Checks if the scanner at the given ID is a direct or java scanner.

Returns:
true there is a native scanner for this id, otherwise false

removeBindings

public boolean removeBindings(JBinding... bindings)

scanAllBindings

public int scanAllBindings(JPacket packet,
                           int offset)
Calculates the next header in sequence of headers within the packet buffer

Parameters:
packet - the packet object this header is bound to
offset - offset into the packet buffer in bytes of the start of this header
Returns:
numerical ID of the next header as assigned by JRegistry

scanHeader

protected void scanHeader(JScan scan)
The main method that this header scanner is called on by the packet scanner, typically from native user space

Parameters:
scan - scan state structure that is used to pass around state both in java and native user space

setScannerMethod

public void setScannerMethod(AnnotatedScannerMethod method)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hasScanMethod

public boolean hasScanMethod()
Returns: