public final class PcapWriteHandler extends io.netty.channel.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. | 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(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
void |
close()
Close
PcapWriter and OutputStream. |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
bind, close, connect, deregister, disconnect, flush, readchannelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredensureNotSharable, handlerAdded, isSharablepublic 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
NullPointerExceptionpublic 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
NullPointerExceptionpublic void channelActive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelActive in interface io.netty.channel.ChannelInboundHandlerchannelActive in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg)
throws Exception
channelRead in interface io.netty.channel.ChannelInboundHandlerchannelRead in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise)
throws Exception
write in interface io.netty.channel.ChannelOutboundHandlerwrite in class io.netty.channel.ChannelDuplexHandlerExceptionpublic void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterExceptionpublic void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
throws Exception
exceptionCaught in interface io.netty.channel.ChannelHandlerexceptionCaught in interface io.netty.channel.ChannelInboundHandlerexceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void close()
throws IOException
Close PcapWriter and OutputStream.
Note: Calling this method does not close PcapWriteHandler.
Only Pcap Writes are closed.
close in interface Closeableclose in interface AutoCloseableIOException - If OutputStream.close() throws an exceptionCopyright © 2008–2021 The Netty Project. All rights reserved.