org.jnetstream.filter.bpf
Class BPFInstruction

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

public class BPFInstruction
extends java.lang.Object

A single instruction of a BPF binary program. This is the equivelement to an assembly instruction. The representation here is more java friendly.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
static class BPFInstruction.Symbol
           
 
Field Summary
 int code
           
 int jf
           
 int jt
           
 long k
           
 BPFInstruction.Symbol symbol
           
 
Constructor Summary
BPFInstruction(byte[] buf, int offset, java.nio.ByteOrder encoding)
          Initializes the instruction from raw buffer data.
BPFInstruction(java.nio.ByteBuffer buf, int offset)
          Initializes the instruction from raw buffer data.
BPFInstruction(int code, int jt, int jf, int k)
           
BPFInstruction(int code, int jt, int jf, long k)
           
 
Method Summary
 byte[] encodeToBinary()
           
static byte[] encodeToBinary(BPFInstruction[] inst)
          Converts an array of BPF instructions to a binary program stored in a buffer.
 int getCode()
           
 int getJf()
           
 int getJt()
           
 long getK()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

code

public final int code

jf

public final int jf

jt

public final int jt

k

public final long k

symbol

public final BPFInstruction.Symbol symbol
Constructor Detail

BPFInstruction

public BPFInstruction(byte[] buf,
                      int offset,
                      java.nio.ByteOrder encoding)
               throws IllegalInstructionException
Initializes the instruction from raw buffer data. Each instruction is 64-bits wide and has the following structure:
 
 struct bpf_insn { u_short code; u_char jt; u_char jf; bpf_int32 k; };
 
 

Parameters:
buf - buffer to extract the structure from
offset - offset within the buffer to read the structure
Throws:
IllegalInstructionException

BPFInstruction

public BPFInstruction(java.nio.ByteBuffer buf,
                      int offset)
Initializes the instruction from raw buffer data. Each instruction is 64-bits wide and has the following structure:
 
 struct bpf_insn { u_short code; u_char jt; u_char jf; bpf_int32 k; };
 
 

Parameters:
buf - buffer to extract the structure from
offset - offset within the buffer to read the structure

BPFInstruction

public BPFInstruction(int code,
                      int jt,
                      int jf,
                      int k)
               throws IllegalInstructionException
Throws:
IllegalInstructionException

BPFInstruction

public BPFInstruction(int code,
                      int jt,
                      int jf,
                      long k)
Parameters:
code - BPF op code
jt - jump address
jf - jump address
k - base offset
Method Detail

encodeToBinary

public static byte[] encodeToBinary(BPFInstruction[] inst)
Converts an array of BPF instructions to a binary program stored in a buffer.

Parameters:
inst - instruction array to do the conversion of
Returns:
buffer containing the converted binary bpf program

encodeToBinary

public byte[] encodeToBinary()
Returns:

getCode

public final int getCode()
Returns:
Returns the code.

getJf

public final int getJf()
Returns:
Returns the jf.

getJt

public final int getJt()
Returns:
Returns the jt.

getK

public final long getK()
Returns:
Returns the k.

toString

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