org.savarese.vserv.ipq
Class NetfilterPacket

java.lang.Object
  extended by org.savarese.vserv.ipq.NetfilterPacket

public class NetfilterPacket
extends java.lang.Object

NetfilterPacket encapsulates a data packet received via the netfilter user space queue. It works in conjunction with NetlinkMessage.getPacket(org.savarese.vserv.ipq.NetfilterPacket).

Author:
Daniel F. Savarese

Field Summary
static int HOOK_LOCAL_FORWARD
           
static int HOOK_LOCAL_IN
           
static int HOOK_LOCAL_OUT
           
static int HOOK_POST_ROUTING
           
static int HOOK_PRE_ROUTING
           
 
Constructor Summary
NetfilterPacket()
          Creates an empty packet that can be used and reused for calls to NetlinkMessage.getPacket(org.savarese.vserv.ipq.NetfilterPacket).
 
Method Summary
 void getHardwareAddress(byte[] address)
          Fetches the hardware address as an array of bytes.
 int getHardwareAddressLength()
          Returns the number of bytes in the hardware address.
 int getHardwareProtocol()
           
 int getHardwareType()
           
 int getHook()
           
 long getID()
           
 void getIncomingInterface(java.lang.StringBuffer buffer)
          Writes in a StringBuffer the name of the network interface over which the packet arrived.
 long getMark()
           
 void getOutgoingInterface(java.lang.StringBuffer buffer)
          Writes in a StringBuffer the name of the network interface over which the packet is exiting.
 void getPacketData(byte[] data)
          Fetches the packet data.
 long getPacketDataLength()
          Returns the number of bytes in the packet data.
 long getTimestampMicroseconds()
           
 long getTimestampSeconds()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOOK_PRE_ROUTING

public static final int HOOK_PRE_ROUTING
See Also:
Constant Field Values

HOOK_LOCAL_IN

public static final int HOOK_LOCAL_IN
See Also:
Constant Field Values

HOOK_LOCAL_FORWARD

public static final int HOOK_LOCAL_FORWARD
See Also:
Constant Field Values

HOOK_LOCAL_OUT

public static final int HOOK_LOCAL_OUT
See Also:
Constant Field Values

HOOK_POST_ROUTING

public static final int HOOK_POST_ROUTING
See Also:
Constant Field Values
Constructor Detail

NetfilterPacket

public NetfilterPacket()
Creates an empty packet that can be used and reused for calls to NetlinkMessage.getPacket(org.savarese.vserv.ipq.NetfilterPacket).

Method Detail

getID

public long getID()
Returns:
The netfilter id of the packet. No special support is provided to interpret this value.

getMark

public long getMark()
Returns:
The netfilter mark value. No special support is provided to interpret this value.

getTimestampSeconds

public long getTimestampSeconds()
Returns:
The time of arrival of the packet in seconds since 1970.

getTimestampMicroseconds

public long getTimestampMicroseconds()
Returns:
The number of microseconds to add to the seconds in the timestamp to get the full time of arrival of the packet.

getHook

public int getHook()
Returns:
An integer, corresponding to one of the HOOK_ constants, indicating the netfilter hook that placed this packet on the user space queue.

getIncomingInterface

public void getIncomingInterface(java.lang.StringBuffer buffer)
Writes in a StringBuffer the name of the network interface over which the packet arrived. For example, eth0 or lo.

Parameters:
buffer - The StringBuffer to which the incoming network interface name should be appened.

getOutgoingInterface

public void getOutgoingInterface(java.lang.StringBuffer buffer)
Writes in a StringBuffer the name of the network interface over which the packet is exiting. For example, eth0 or lo.

Parameters:
buffer - The StringBuffer to which the outgoing network interface name should be appened.

getHardwareProtocol

public int getHardwareProtocol()
Returns:
The hardware protocol. No special support is provided to interpret t this value.

getHardwareType

public int getHardwareType()
Returns:
The hardware type. No special support is provided to interpret this value.

getHardwareAddressLength

public int getHardwareAddressLength()
Returns the number of bytes in the hardware address. You'd call this method first to determine how large of an array to allocate before calling getHardwareAddress(byte[]).

Returns:
The number of bytes in the hardware address.

getHardwareAddress

public void getHardwareAddress(byte[] address)
Fetches the hardware address as an array of bytes. If you were to print each byte as a hexadecimal number, you'd get the familiar Ethernet hardware address.

Parameters:
address - The array in which to store the address.

getPacketDataLength

public long getPacketDataLength()
Returns the number of bytes in the packet data. You'd call this method first to determine thow large of an array to allocate before calling getPacketData(byte[]).

Returns:
The number of bytes in the packet data.

getPacketData

public void getPacketData(byte[] data)
Fetches the packet data.

Parameters:
data - The array in which to store the packet data.