org.jnetpcap.winpcap
Class WinPcapSendQueue

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JStruct
          extended by org.jnetpcap.winpcap.WinPcapSendQueue

public class WinPcapSendQueue
extends JStruct

Class peered with native pcap_send_queue structure. A queue of raw packets that will be sent to the network with WinPcap.sendqueueTransmit(). The class peers with native C pcap_send_queue structure and allows direct control. The structure can be allocated using WinPcap.sendQueueAlloc method or can be directly instantiated using one of the public constructors.

Here is an example:

 WinPcapSendQueue queue = WinPcap.sendQueueAlloc(512);
 PcapHeader hdr = new PcapHeader(128, 128);
 byte[] pkt = new byte[128];
 
 Arrays.fill(pkt, (byte) 255); // Broadcast
 queue.queue(hdr, pkt); // Packet #1
 queue.queue(hdr, pkt); // Packet #2
 
 Arrays.fill(pkt, (byte) 0x11); // Junk packet
 queue.queue(hdr, pkt); // Packet #3
 
 r = pcap.sendQueueTransmit(queue, WinPcap.TRANSMIT_SYNCH_ASAP);
 if (r != queue.getLen()) {
        System.err.println(pcap.getErr());
        return;
 }
 
 

Author:
Sly Technologies, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory
JMemory.Type
 
Field Summary
static int DEFAULT_QUEUE_SIZE
          Constant used to determine the default queue size which is 64Kb (1024 * 64).
static java.lang.String STRUCT_NAME
          The Constant STRUCT_NAME.
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER
 
Constructor Summary
WinPcapSendQueue()
          Allocates default size buffer for use as a send queue.
WinPcapSendQueue(byte[] data)
          Creates a sendqueue by allocating a buffer to hold the supplied data.
WinPcapSendQueue(java.nio.ByteBuffer buffer)
           The queue uses the supplied byte buffer which holds the buffers contents.
WinPcapSendQueue(int size)
          Allocates specific queue size.
 
Method Summary
 JBuffer getBuffer()
          Gets the buffer containing the packets to be sent.
 int getLen()
          Gets the current size of the queue, in bytes.
 int getMaxLen()
          Gets the maximum size of the the queue, in bytes.
 int incLen(int delta)
          Inc len.
 int queue(PcapHeader header, byte[] data)
          Add a packet to a send queue.
 int queue(PcapHeader header, java.nio.ByteBuffer data)
          Add a packet to a send queue.
 int queue(PcapHeader header, JBuffer data)
          Add a packet to a send queue.
 int queue(PcapPktHdr hdr, byte[] data)
          Deprecated. replaced with new versions of the same method
 int queue(PcapPktHdr hdr, java.nio.ByteBuffer data)
          Deprecated. replaced with new versions of the same method
 void setLen(int len)
          Sets the peered pcap_send_queue.len field which specifies the urrent size of the queue, in bytes.
 void setMaxLen(int len)
          Sets the max len.
static int sizeof()
          Returns sizeof struct pcap_send_queue.
 java.lang.String toDebugString()
          Returns a string with detailed information about the underlying pcap_send_queue structure.
 
Methods inherited from class org.jnetpcap.nio.JStruct
getStructName, toString
 
Methods inherited from class org.jnetpcap.nio.JMemory
availableDirectMemory, check, cleanup, createReference, isInitialized, isJMemoryBasedOwner, isOwner, maxDirectMemory, peer, peer, peer, reservedDirectMemory, setSize, size, softDirectMemory, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_QUEUE_SIZE

public static final int DEFAULT_QUEUE_SIZE
Constant used to determine the default queue size which is 64Kb (1024 * 64).

See Also:
Constant Field Values

STRUCT_NAME

public static final java.lang.String STRUCT_NAME
The Constant STRUCT_NAME.

See Also:
Constant Field Values
Constructor Detail

WinPcapSendQueue

public WinPcapSendQueue()
Allocates default size buffer for use as a send queue.


WinPcapSendQueue

public WinPcapSendQueue(byte[] data)
Creates a sendqueue by allocating a buffer to hold the supplied data. The data array is copied into the buffer.

Parameters:
data - data to be copied into the queue

WinPcapSendQueue

public WinPcapSendQueue(java.nio.ByteBuffer buffer)
                 throws PeeringException

The queue uses the supplied byte buffer which holds the buffers contents. The buffer must a direct buffer, array based buffers will be rejected and an exception thrown. The properties of the buffer are used as follows. The start of the buffer is always with index 0, and end of queue content at current buffer's limit property (comparible to pcap_send_queue.len). The capacity property (comparible to pcap_send_queue.maxlen) determines maximum amount of data that can be further stored in the buffer.

Note that changing properties of the buffer after creating this queue object, will have immediate effect up on the queue. You do not have to use the queue's provided methods to change the limit property. This should allow of external addition of the

Parameters:
buffer - a direct buffer containing the data to be send
Throws:
PeeringException - the peering exception

WinPcapSendQueue

public WinPcapSendQueue(int size)
Allocates specific queue size.

Parameters:
size - size of the queue in bytes
Method Detail

sizeof

public static int sizeof()
Returns sizeof struct pcap_send_queue.

Returns:
size of structure

getBuffer

public JBuffer getBuffer()
Gets the buffer containing the packets to be sent.

Returns:
buffer containing the packets to be sent

getLen

public int getLen()
Gets the current size of the queue, in bytes.

Returns:
current size of the queue, in bytes

getMaxLen

public int getMaxLen()
Gets the maximum size of the the queue, in bytes. This variable contains the size of the buffer field.

Returns:
maximum size of the the queue, in bytes

incLen

public int incLen(int delta)
Inc len.

Parameters:
delta - the delta
Returns:
the int

queue

public int queue(PcapHeader header,
                 byte[] data)
Add a packet to a send queue. This method adds a packet at the end of the send queue pointed by the queue parameter. hdr points to a PcapPktHdr structure with the timestamp and the length of the packet, data points to a buffer with the data of the packet. The PcapPktHdr structure is the same used by WinPcap and libpcap to store the packets in a file, therefore sending a capture file is straightforward. 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface.

Parameters:
header - all fields need to be initialized as they are all used
data - Buffer containing packet data. The buffer's position and limit properties determine the area of the buffer to be copied into the queue. The length of the data must much what is in the header. Also the queue has to be large enough to hold all of the data, or an exception will be thrown.
Returns:
0 (Pcap.OK) on success; exception thrown on failure

queue

public int queue(PcapHeader header,
                 java.nio.ByteBuffer data)
Add a packet to a send queue. This method adds a packet at the end of the send queue pointed by the queue parameter. hdr points to a PcapPktHdr structure with the timestamp and the length of the packet, data points to a buffer with the data of the packet. The PcapPktHdr structure is the same used by WinPcap and libpcap to store the packets in a file, therefore sending a capture file is straightforward. 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface.

Parameters:
header - all fields need to be initialized as they are all used
data - Buffer containing packet data. The buffer's position and limit properties determine the area of the buffer to be copied into the queue. The length of the data must much what is in the header. Also the queue has to be large enough to hold all of the data, or an exception will be thrown.
Returns:
0 (Pcap.OK) on success; exception thrown on failure

queue

public int queue(PcapHeader header,
                 JBuffer data)
Add a packet to a send queue. This method adds a packet at the end of the send queue pointed by the queue parameter. hdr points to a PcapPktHdr structure with the timestamp and the length of the packet, data points to a buffer with the data of the packet. The PcapPktHdr structure is the same used by WinPcap and libpcap to store the packets in a file, therefore sending a capture file is straightforward. 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface.

Parameters:
header - all fields need to be initialized as they are all used
data - Buffer containing packet data. The buffer's position and limit properties determine the area of the buffer to be copied into the queue. The length of the data must much what is in the header. Also the queue has to be large enough to hold all of the data, or an exception will be thrown.
Returns:
0 (Pcap.OK) on success; exception thrown on failure

queue

@Deprecated
public int queue(PcapPktHdr hdr,
                            byte[] data)
Deprecated. replaced with new versions of the same method

Add a packet to a send queue. This method adds a packet at the end of the send queue pointed by the queue parameter. hdr points to a PcapPktHdr structure with the timestamp and the length of the packet, data points to a buffer with the data of the packet. The PcapPktHdr structure is the same used by WinPcap and libpcap to store the packets in a file, therefore sending a capture file is straightforward. 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface.

Parameters:
hdr - all fields need to be initialized as they are all used
data - Buffer containing packet data. The length of the data must much what is in the header. Also the queue has to be large enough to hold all of the data, or an exception will be thrown.
Returns:
0 on success; exception thrown on failure

queue

@Deprecated
public int queue(PcapPktHdr hdr,
                            java.nio.ByteBuffer data)
Deprecated. replaced with new versions of the same method

Add a packet to a send queue. This method adds a packet at the end of the send queue pointed by the queue parameter. hdr points to a PcapPktHdr structure with the timestamp and the length of the packet, data points to a buffer with the data of the packet. The PcapPktHdr structure is the same used by WinPcap and libpcap to store the packets in a file, therefore sending a capture file is straightforward. 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface.

Parameters:
hdr - all fields need to be initialized as they are all used
data - Buffer containing packet data. The buffer's position and limit properties determine the area of the buffer to be copied into the queue. The length of the data must much what is in the header. Also the queue has to be large enough to hold all of the data, or an exception will be thrown.
Returns:
0 on success; exception thrown on failure

setLen

public void setLen(int len)
Sets the peered pcap_send_queue.len field which specifies the urrent size of the queue, in bytes.

Parameters:
len - current size of the queue, in bytes

setMaxLen

public void setMaxLen(int len)
Sets the max len.

Parameters:
len - the new max len

toDebugString

public java.lang.String toDebugString()
Returns a string with detailed information about the underlying pcap_send_queue structure.

Overrides:
toDebugString in class JMemory
Returns:
String with debug information
See Also:
JMemory.toDebugString()