public final class PcapWriteHandler extends ChannelDuplexHandler implements Closeable
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. ChannelHandlerAdapter.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
. ChannelHandler.Sharable
Constructor and Description |
---|
PcapWriteHandler(OutputStream outputStream)
Create new
PcapWriteHandler Instance. |
PcapWriteHandler(OutputStream outputStream,
boolean captureZeroByte,
boolean writePcapGlobalHeader)
Create new
PcapWriteHandler Instance |
Modifier and Type | Method and Description |
---|---|
void |
channelActive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelActive() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
void |
channelRead(ChannelHandlerContext ctx,
Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
void |
close()
Close
PcapWriter and OutputStream . |
void |
exceptionCaught(ChannelHandlerContext ctx,
Throwable cause)
Calls
ChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline . |
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline . |
bind, close, connect, deregister, disconnect, flush, read
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerAdded, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded
public PcapWriteHandler(OutputStream outputStream)
PcapWriteHandler
Instance.
captureZeroByte
is set to false
and
writePcapGlobalHeader
is set to true
.outputStream
- OutputStream where Pcap data will be written. Call close()
to close this
OutputStream.NullPointerException
- If OutputStream
is null
then we'll throw an
NullPointerException
public PcapWriteHandler(OutputStream outputStream, boolean captureZeroByte, boolean writePcapGlobalHeader)
PcapWriteHandler
InstanceoutputStream
- OutputStream where Pcap data will be written. Call close()
to close this
OutputStream.captureZeroByte
- Set to true
to enable capturing packets with empty (0 bytes) payload.
Otherwise, if set to false
, empty packets will be filtered out.writePcapGlobalHeader
- Set to 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.NullPointerException
- If OutputStream
is null
then we'll throw an
NullPointerException
public void channelActive(ChannelHandlerContext ctx) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelActive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelActive
in interface ChannelInboundHandler
channelActive
in class ChannelInboundHandlerAdapter
Exception
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelInboundHandler
channelRead
in class ChannelInboundHandlerAdapter
Exception
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelDuplexHandler
ChannelOutboundInvoker.write(Object, ChannelPromise)
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.write
in interface ChannelOutboundHandler
write
in class ChannelDuplexHandler
ctx
- the ChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- the ChannelPromise
to notify once the operation completesException
- thrown if an error occurspublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerRemoved
in interface ChannelHandler
handlerRemoved
in class ChannelHandlerAdapter
Exception
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.exceptionCaught
in interface ChannelHandler
exceptionCaught
in interface ChannelInboundHandler
exceptionCaught
in class ChannelInboundHandlerAdapter
Exception
public void close() throws IOException
Close PcapWriter
and OutputStream
.
Note: Calling this method does not close PcapWriteHandler
.
Only Pcap Writes are closed.
close
in interface Closeable
close
in interface AutoCloseable
IOException
- If OutputStream.close()
throws an exceptionCopyright © 2008–2021 The Netty Project. All rights reserved.