Class PcapWriteHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.pcap.PcapWriteHandler
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler, Closeable, AutoCloseable
PcapWriteHandler captures ByteBuf from SocketChannel / ServerChannel
or DatagramPacket and writes it into Pcap OutputStream.
Things to keep in mind when using PcapWriteHandler with TCP:
- Whenever
ChannelInboundHandlerAdapter.channelActive(ChannelHandlerContext)is called, a fake TCP 3-way handshake (SYN, SYN+ACK, ACK) is simulated as new connection in Pcap. - Whenever
ChannelHandlerAdapter.handlerRemoved(ChannelHandlerContext)is called, a fake TCP 3-way handshake (FIN+ACK, FIN+ACK, ACK) is simulated as connection shutdown in Pcap. - Whenever
ChannelInboundHandlerAdapter.exceptionCaught(ChannelHandlerContext, Throwable)is called, a fake TCP RST is sent to simulate connection Reset in Pcap. - ACK is sent each time data is send / received.
- Zero Length Data Packets can cause TCP Double ACK error in Wireshark. To tackle this,
set
captureZeroBytetofalse.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionPcapWriteHandler(OutputStream outputStream) Deprecated.PcapWriteHandler(OutputStream outputStream, boolean captureZeroByte, boolean writePcapGlobalHeader) Deprecated.UsePcapWriteHandler.Builderinstead. -
Method Summary
Modifier and TypeMethodDescriptionstatic PcapWriteHandler.Builderbuilder()voidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidclose()ClosePcapWriterandOutputStream.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.voidDo nothing by default, sub-classes may override this method.booleanReturnstrueif thePcapWriteHandleris currently writing packets to theOutputStreamelse returnsfalse.voidpause()Pause thePcapWriteHandlerfrom writing packets to theOutputStream.voidresume()Resume thePcapWriteHandlerto writing packets to theOutputStream.toString()voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.static voidwriteGlobalHeader(OutputStream outputStream) Writes the Pcap Global Header to the providedOutputStreamMethods inherited from class ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class ChannelInboundHandlerAdapter
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ChannelHandler
handlerAdded
-
Constructor Details
-
PcapWriteHandler
Deprecated.UsePcapWriteHandler.Builderinstead.Create newPcapWriteHandlerInstance.captureZeroByteis set tofalseandwritePcapGlobalHeaderis set totrue.- Parameters:
outputStream- OutputStream where Pcap data will be written. Callclose()to close this OutputStream.- Throws:
NullPointerException- IfOutputStreamisnullthen we'll throw anNullPointerException
-
PcapWriteHandler
@Deprecated public PcapWriteHandler(OutputStream outputStream, boolean captureZeroByte, boolean writePcapGlobalHeader) Deprecated.UsePcapWriteHandler.Builderinstead.Create newPcapWriteHandlerInstance- Parameters:
outputStream- OutputStream where Pcap data will be written. Callclose()to close this OutputStream.captureZeroByte- Set totrueto enable capturing packets with empty (0 bytes) payload. Otherwise, if set tofalse, empty packets will be filtered out.writePcapGlobalHeader- Set totrueto write Pcap Global Header on initialization. Otherwise, if set tofalse, 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.- Throws:
NullPointerException- IfOutputStreamisnullthen we'll throw anNullPointerException
-
-
Method Details
-
writeGlobalHeader
Writes the Pcap Global Header to the providedOutputStream- Parameters:
outputStream- OutputStream where Pcap data will be written.- Throws:
IOException- if there is an error writing to theOutputStream
-
channelActive
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelActivein interfaceChannelInboundHandler- Overrides:
channelActivein classChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin classChannelInboundHandlerAdapter- Throws:
Exception
-
write
Description copied from class:ChannelDuplexHandlerCallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
writein interfaceChannelOutboundHandler- Overrides:
writein classChannelDuplexHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to writepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
Exception
-
exceptionCaught
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaughtin interfaceChannelHandler- Specified by:
exceptionCaughtin interfaceChannelInboundHandler- Overrides:
exceptionCaughtin classChannelInboundHandlerAdapter- Throws:
Exception
-
isWriting
public boolean isWriting()Returnstrueif thePcapWriteHandleris currently writing packets to theOutputStreamelse returnsfalse. -
pause
public void pause()Pause thePcapWriteHandlerfrom writing packets to theOutputStream. -
resume
public void resume()Resume thePcapWriteHandlerto writing packets to theOutputStream. -
toString
-
close
Close
PcapWriterandOutputStream.Note: Calling this method does not close
PcapWriteHandler. Only Pcap Writes are closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- IfOutputStream.close()throws an exception
-
builder
-
PcapWriteHandler.Builderinstead.