Package io.netty.handler.pcap
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:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler,Closeable,AutoCloseable
public final class PcapWriteHandler extends io.netty.channel.ChannelDuplexHandler implements Closeable
PcapWriteHandlercapturesByteBuffromSocketChannel/ServerChannelorDatagramPacketand writes it into PcapOutputStream.Things to keep in mind when using
PcapWriteHandlerwith 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 Classes Modifier and Type Class Description static classPcapWriteHandler.BuilderBuilder forPcapWriteHandler
-
Constructor Summary
Constructors Constructor Description PcapWriteHandler(OutputStream outputStream)Deprecated.UsePcapWriteHandler.Builderinstead.PcapWriteHandler(OutputStream outputStream, boolean captureZeroByte, boolean writePcapGlobalHeader)Deprecated.UsePcapWriteHandler.Builderinstead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PcapWriteHandler.Builderbuilder()voidchannelActive(io.netty.channel.ChannelHandlerContext ctx)voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)voidclose()ClosePcapWriterandOutputStream.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)booleanisWriting()Returnstrueif thePcapWriteHandleris currently writing packets to theOutputStreamelse returnsfalse.voidpause()Pause thePcapWriteHandlerfrom writing packets to theOutputStream.voidresume()Resume thePcapWriteHandlerto writing packets to theOutputStream.StringtoString()voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)static voidwriteGlobalHeader(OutputStream outputStream)Writes the Pcap Global Header to the providedOutputStream-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharable
-
-
-
-
Constructor Detail
-
PcapWriteHandler
@Deprecated public PcapWriteHandler(OutputStream outputStream)
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 Detail
-
writeGlobalHeader
public static void writeGlobalHeader(OutputStream outputStream) throws IOException
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
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- 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.
-
close
public void close() throws IOExceptionClose
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
public static PcapWriteHandler.Builder builder()
-
-