org.jnetstream.filter.bpf
Class BPFProgram

java.lang.Object
  extended by org.jnetstream.filter.bpf.BPFProgram

public class BPFProgram
extends java.lang.Object

A set of instructions compiled from a textual expression to a binary level which can be passed to a BPF VM for interpretation.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Constructor Summary
BPFProgram(BPFInstruction[] code, java.nio.ByteOrder order)
           
BPFProgram(byte[] pc)
          Compiles the supplied rawBuffer BPF byte code array into a more java friendly BPFInstruction program.
BPFProgram(java.lang.String tcpdumpText)
          Initializes this BPF program from a tcpdump/libpcap generated pseudo code.
 
Method Summary
static BPFInstruction[] convertBE(byte[] program)
          Converts a rawBuffer byte[] byte code into an array of more java friendly BPFInstructions.
static BPFInstruction[] convertLE(byte[] program)
          Converts a rawBuffer byte[] code into an array of more java friendly BPFInstructions.
 BPFInstruction[] getCode()
          Gets the java friendly compiled BPF instruction code.
 java.nio.ByteOrder getEncoding()
          Gets the byte encoding of this program.
 int getLength()
           
 java.nio.ByteBuffer getRawBuffer()
          Gets the raw byte code of this bpf program.
 java.lang.StringBuilder toBuffer(java.lang.StringBuilder buf)
           
 java.lang.StringBuilder toBufferCode(java.lang.StringBuilder buf)
           
 java.lang.String toString()
           
 java.lang.String toStringCode()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BPFProgram

public BPFProgram(BPFInstruction[] code,
                  java.nio.ByteOrder order)

BPFProgram

public BPFProgram(byte[] pc)
           throws IllegalInstructionException
Compiles the supplied rawBuffer BPF byte code array into a more java friendly BPFInstruction program.

Throws:
IllegalInstructionException - if an unrecognized instruction is encountered in the pc array

BPFProgram

public BPFProgram(java.lang.String tcpdumpText)
           throws IllegalInstructionException
Initializes this BPF program from a tcpdump/libpcap generated pseudo code. The pseudo code is compiled to binary form and initialized.

Parameters:
tcpdumpText - the pseudo code as generated by tcpdump/libpcap tools
Throws:
IllegalInstructionException - if an unrecognized instruction is encountered
Method Detail

convertBE

public static BPFInstruction[] convertBE(byte[] program)
                                  throws IllegalInstructionException
Converts a rawBuffer byte[] byte code into an array of more java friendly BPFInstructions. The instructions are assumed to be in big-endian (most significant) byte order.

Parameters:
program - the rawBuffer byte code program to convert
Returns:
converted program to an instruction array
Throws:
IllegalInstructionException - if an unrecognized instruction is encountered

convertLE

public static BPFInstruction[] convertLE(byte[] program)
                                  throws IllegalInstructionException
Converts a rawBuffer byte[] code into an array of more java friendly BPFInstructions. The instructions are assumed to be in little-endian (least significant) byte order.

Parameters:
program - the rawBuffer byte code program to convert
Returns:
converted program to an instruction array
Throws:
IllegalInstructionException - if an unrecognized instruction is encountered

getCode

public final BPFInstruction[] getCode()
Gets the java friendly compiled BPF instruction code.

Returns:
Returns the code.

getEncoding

public final java.nio.ByteOrder getEncoding()
Gets the byte encoding of this program.

Returns:
Returns the encoding.

getLength

public final int getLength()
Returns:
Returns the length.

getRawBuffer

public final java.nio.ByteBuffer getRawBuffer()
Gets the raw byte code of this bpf program.

Returns:
Returns the rawBuffer that contains the raw BPF byte code.

toBuffer

public java.lang.StringBuilder toBuffer(java.lang.StringBuilder buf)
Parameters:
buf -
Returns:

toBufferCode

public java.lang.StringBuilder toBufferCode(java.lang.StringBuilder buf)

toString

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

toStringCode

public java.lang.String toStringCode()
Returns: