PcapWriteHandler captures ByteBuf from SocketChannel / ServerChannel
or DatagramPacket and writes it into Pcap OutputStream.
Things to keep in mind when using PcapWriteHandler with TCP:
ChannelInboundHandlerAdapter#channelActive(ChannelHandlerContext) is called,
a fake TCP 3-way handshake (SYN, SYN+ACK, ACK) is simulated as new connection in Pcap. ChannelInboundHandlerAdapter#handlerRemoved(ChannelHandlerContext) is called,
a fake TCP 3-way handshake (FIN+ACK, FIN+ACK, ACK) is simulated as connection shutdown in Pcap. ChannelInboundHandlerAdapter#exceptionCaught(ChannelHandlerContext, Throwable)
is called, a fake TCP RST is sent to simulate connection Reset in Pcap. captureZeroByte to false. | Modifier and Type | Class and Description |
|---|---|
| public static class | PcapWriteHandler.
Builder for |
| private static enum | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | captureZeroByte
|
| private PcapWriteHandler. | channelType
Type of the channel this handler is registered on |
| private InetSocketAddress | handlerAddr
Address of the receiver of the connection |
| private InetSocketAddress | initiatorAddr
Address of the initiator of the connection |
| private boolean | isServerPipeline
Set to |
| private final InternalLogger | logger
Logger for logging events |
| private final OutputStream | outputStream
|
| private PcapWriter | pCapWriter
|
| private int | receiveSegmentNumber
TCP Receiver Segment Number. |
| private int | sendSegmentNumber
TCP Sender Segment Number. |
| private final boolean | sharedOutputStream
|
| private final AtomicReference | state
Current of this |
| private final boolean | writePcapGlobalHeader
|
| Access | Constructor and Description |
|---|---|
| public | PcapWriteHandler(OutputStream
OutputStream where Pcap data will be written. Call outputStream)close() to close this
OutputStream.
Deprecated
Use
Create new Builder instead.
PcapWriteHandler Instance.
|
| public | PcapWriteHandler(OutputStream
OutputStream where Pcap data will be written. Call outputStream, boolean close() to close this
OutputStream.Set to captureZeroByte, boolean true to enable capturing packets with empty (0 bytes) payload.
Otherwise, if set to false, empty packets will be filtered out.Set to writePcapGlobalHeader)true to write Pcap Global Header on initialization.
Otherwise, if set to false, Pcap Global Header will not be written
on initialization. This could when writing Pcap data on a existing file where
Pcap Global Header is already present.
Deprecated
Use
Create new Builder instead.
PcapWriteHandler Instance
|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static PcapWriteHandler. | |
| public void | channelActive(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandlerContext#fireChannelActive() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| public void | channelRead(ChannelHandlerContext ctx, Object msg)
Overrides io. Implements io. ChannelHandlerContext#fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| public void | |
| private void | completeTCPWrite(InetSocketAddress
InetSocketAddress Source Address of this PacketInetSocketAddress Destination Address of this PacketByteBuf containing TCP L4 DataByteBufAllocator for allocating bytes for TCP/IP L3 and L2 data.ChannelHandlerContext for fireExceptionCaughtWrite TCP/IP L3 and L2 here. |
| private void | completeUDPWrite(InetSocketAddress
InetSocketAddress Source Address of this PacketInetSocketAddress Destination Address of this PacketByteBuf containing UDP L4 DataByteBufAllocator for allocating bytes for UDP/IP L3 and L2 data.ChannelHandlerContext for fireExceptionCaughtWrite UDP/IP L3 and L2 here. |
| public void | exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Overrides io. Implements io. Throwable was thrown.
|
| private static InetSocketAddress | Returns: The fixed local addressThe channel to get the local address from ch, InetSocketAddress The remote address remote)Get the local address of a channel. |
| public void | handlerRemoved(ChannelHandlerContext ctx)
Overrides io. Implements io. ChannelHandler was removed from the actual context and it doesn't handle events
anymore.
|
| private void | handleTCP(ChannelHandlerContext ctx, Object msg, boolean
Set isWriteOperation)true if we have to process packet when packets are being sent out
else set falseHandle TCP L4 |
| private void | |
| private void | |
| public boolean | isWriting()
Returns |
| private void | |
| private void | logTCP(boolean isWriteOperation, int bytes, int sendSegmentNumber, int receiveSegmentNumber, InetSocketAddress srcAddr, InetSocketAddress dstAddr, boolean ackOnly)
Logger for TCP |
| pack-priv void | |
| pack-priv OutputStream | |
| public void | |
| pack-priv PcapWriter | |
| public void | |
| pack-priv boolean | |
| pack-priv State | |
| public String | |
| public void | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg, ChannelPromise the promise)ChannelPromise to notify once the operation completesOverrides io. Implements io. ChannelHandlerContext#write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
|
| public static void | writeGlobalHeader(OutputStream
OutputStream where Pcap data will be written. outputStream)Writes the Pcap Global Header to the provided |
| captureZeroByte | back to summary |
|---|---|
| private final boolean captureZeroByte
| |
| channelType | back to summary |
|---|---|
| private PcapWriteHandler. Type of the channel this handler is registered on | |
| handlerAddr | back to summary |
|---|---|
| private InetSocketAddress handlerAddr Address of the receiver of the connection | |
| initiatorAddr | back to summary |
|---|---|
| private InetSocketAddress initiatorAddr Address of the initiator of the connection | |
| isServerPipeline | back to summary |
|---|---|
| private boolean isServerPipeline Set to | |
| logger | back to summary |
|---|---|
| private final InternalLogger logger Logger for logging events | |
| outputStream | back to summary |
|---|---|
| private final OutputStream outputStream
| |
| pCapWriter | back to summary |
|---|---|
| private PcapWriter pCapWriter
| |
| receiveSegmentNumber | back to summary |
|---|---|
| private int receiveSegmentNumber TCP Receiver Segment Number. It'll start with 1 and keep incrementing with number of bytes read/sent. | |
| sendSegmentNumber | back to summary |
|---|---|
| private int sendSegmentNumber TCP Sender Segment Number. It'll start with 1 and keep incrementing with number of bytes read/sent. | |
| sharedOutputStream | back to summary |
|---|---|
| private final boolean sharedOutputStream
| |
| state | back to summary |
|---|---|
| private final AtomicReference<State> state Current of this | |
| writePcapGlobalHeader | back to summary |
|---|---|
| private final boolean writePcapGlobalHeader
| |
| PcapWriteHandler | back to summary |
|---|---|
| public PcapWriteHandler(OutputStream outputStream)
Deprecated Use Create new
| |
| PcapWriteHandler | back to summary |
|---|---|
| public PcapWriteHandler(OutputStream outputStream, boolean captureZeroByte, boolean writePcapGlobalHeader)
Deprecated Use Create new
| |
| PcapWriteHandler | back to summary |
|---|---|
| private PcapWriteHandler(PcapWriteHandler. | |
| builder | back to summary |
|---|---|
| public static PcapWriteHandler. | |
| channelActive | back to summary |
|---|---|
| public void channelActive(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| channelRead | back to summary |
|---|---|
| public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Close Note Calling this method does not close
| |
| completeTCPWrite | back to summary |
|---|---|
| private void completeTCPWrite(InetSocketAddress srcAddr, InetSocketAddress dstAddr, ByteBuf tcpBuf, ByteBufAllocator byteBufAllocator, ChannelHandlerContext ctx) Write TCP/IP L3 and L2 here.
| |
| completeUDPWrite | back to summary |
|---|---|
| private void completeUDPWrite(InetSocketAddress srcAddr, InetSocketAddress dstAddr, ByteBuf udpBuf, ByteBufAllocator byteBufAllocator, ChannelHandlerContext ctx) Write UDP/IP L3 and L2 here.
| |
| exceptionCaught | back to summary |
|---|---|
| public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception Overrides io. Implements io. Doc from io. Gets called if a
| |
| getLocalAddress | back to summary |
|---|---|
| private static InetSocketAddress getLocalAddress(Channel ch, InetSocketAddress remote) Get the local address of a channel. If the address is a wildcard address (
| |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Gets called after the
| |
| handleTCP | back to summary |
|---|---|
| private void handleTCP(ChannelHandlerContext ctx, Object msg, boolean isWriteOperation) Handle TCP L4
| |
| handleUDP | back to summary |
|---|---|
| private void handleUDP(ChannelHandlerContext ctx, Object msg) Handle UDP l4
| |
| initializeIfNecessary | back to summary |
|---|---|
| private void initializeIfNecessary(ChannelHandlerContext ctx) throws Exception | |
| isWriting | back to summary |
|---|---|
| public boolean isWriting() Returns | |
| logDiscard | back to summary |
|---|---|
| private void logDiscard() | |
| logTCP | back to summary |
|---|---|
| private void logTCP(boolean isWriteOperation, int bytes, int sendSegmentNumber, int receiveSegmentNumber, InetSocketAddress srcAddr, InetSocketAddress dstAddr, boolean ackOnly) Logger for TCP | |
| markClosed | back to summary |
|---|---|
| pack-priv void markClosed() | |
| outputStream | back to summary |
|---|---|
| pack-priv OutputStream outputStream() | |
| pause | back to summary |
|---|---|
| public void pause() Pause the | |
| pCapWriter | back to summary |
|---|---|
| pack-priv PcapWriter pCapWriter() | |
| resume | back to summary |
|---|---|
| public void resume() Resume the | |
| sharedOutputStream | back to summary |
|---|---|
| pack-priv boolean sharedOutputStream() | |
| state | back to summary |
|---|---|
| pack-priv State state() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| write | back to summary |
|---|---|
| public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| writeGlobalHeader | back to summary |
|---|---|
| public static void writeGlobalHeader(OutputStream outputStream) throws IOException Writes the Pcap Global Header to the provided
| |
PcapWriteHandler
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private PcapWriteHandler. | |
| private InetSocketAddress | |
| private InetSocketAddress | |
| private boolean | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public PcapWriteHandler | Returns: The handler.The output stream to write the pcap data to. outputStream)Build the |
| public PcapWriteHandler. | Returns: this builderWhether to filter out empty packets. captureZeroByte)Set to |
| public PcapWriteHandler. | Returns: this builderThe address of the TCP server (handler) serverAddress, InetSocketAddress The address of the TCP client (initiator) clientAddress, boolean Whether the handler is part of the server channel isServerPipeline)Force this handler to write data as if they were TCP packets, with the given connection metadata. |
| public PcapWriteHandler. | Returns: this builderThe address of the UDP local localAddress, InetSocketAddress The address of the UDP remote remoteAddress)Force this handler to write data as if they were UDP packets, with the given connection metadata. |
| public PcapWriteHandler. | Returns: this builderWhether sharedOutputStream)OutputStream is shared or notSet to |
| public PcapWriteHandler. | Returns: this builderWhether to write the pcap global header. writePcapGlobalHeader)Set to |
| captureZeroByte | back to summary |
|---|---|
| private boolean captureZeroByte | |
| channelType | back to summary |
|---|---|
| private PcapWriteHandler. | |
| handlerAddr | back to summary |
|---|---|
| private InetSocketAddress handlerAddr | |
| initiatorAddr | back to summary |
|---|---|
| private InetSocketAddress initiatorAddr | |
| isServerPipeline | back to summary |
|---|---|
| private boolean isServerPipeline | |
| sharedOutputStream | back to summary |
|---|---|
| private boolean sharedOutputStream | |
| writePcapGlobalHeader | back to summary |
|---|---|
| private boolean writePcapGlobalHeader | |
| Builder | back to summary |
|---|---|
| private Builder() | |
| build | back to summary |
|---|---|
| public PcapWriteHandler build(OutputStream outputStream) Build the
| |
| captureZeroByte | back to summary |
|---|---|
| public PcapWriteHandler. Set to
| |
| forceTcpChannel | back to summary |
|---|---|
| public PcapWriteHandler. Force this handler to write data as if they were TCP packets, with the given connection metadata. If this method isn't called, we determine the metadata from the channel.
| |
| forceUdpChannel | back to summary |
|---|---|
| public PcapWriteHandler. Force this handler to write data as if they were UDP packets, with the given connection metadata. If this
method isn't called, we determine the metadata from the channel.
| |
| sharedOutputStream | back to summary |
|---|---|
| public PcapWriteHandler. Set to Note it is probably an error to have both
| |
| writePcapGlobalHeader | back to summary |
|---|---|
| public PcapWriteHandler. Set to
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final PcapWriteHandler. | |
| public static final PcapWriteHandler. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static PcapWriteHandler. | |
| public static PcapWriteHandler. |
| TCP | back to summary |
|---|---|
| public static final PcapWriteHandler. | |
| UDP | back to summary |
|---|---|
| public static final PcapWriteHandler. | |
| ChannelType | back to summary |
|---|---|
| private ChannelType() | |
| valueOf | back to summary |
|---|---|
| public static PcapWriteHandler. | |
| values | back to summary |
|---|---|
| public static PcapWriteHandler. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final InetAddress | |
| pack-priv static final InetAddress |
| Access | Constructor and Description |
|---|---|
| private |
| wildcard4 | back to summary |
|---|---|
| pack-priv static final InetAddress wildcard4 | |
| wildcard6 | back to summary |
|---|---|
| pack-priv static final InetAddress wildcard6 | |
| WildcardAddressHolder | back to summary |
|---|---|
| private WildcardAddressHolder() | |