public class Pcap extends Object
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
PcapOutputStream |
createOutputStream(OutputStream out)
Create an
PcapOutputStream based on this Pcap. |
PcapGlobalHeader |
getPcapHeader() |
void |
loop(PacketHandler callback) |
static Pcap |
openStream(File file) |
static Pcap |
openStream(InputStream is)
Capture packets from the input stream
|
static Pcap |
openStream(InputStream is,
int bufferCapacity)
Capture packets from the input stream
|
static Pcap |
openStream(String file) |
void |
setFilter(String expression)
It is possible to specify a filter so that only packets that matches the
filter will be passed onto the registered
PacketHandler. |
public void setFilter(String expression) throws FilterParseException
PacketHandler.
E.g., to only accept packets of type sip with the Call-ID of "123" you
could pass in the following filter:
"sip.Call-ID == 123"expression - the expression. If the expression is null or the empty string,
it will silently be ignored.FilterParseException - in case the expression is not a valid filter expression.public void loop(PacketHandler callback) throws IOException, FramingException
IOExceptionFramingExceptionpublic PcapOutputStream createOutputStream(OutputStream out) throws IllegalArgumentException
PcapOutputStream based on this Pcap. The new
PcapOutputStream is configured to use the same
PcapGlobalHeader as the Pcap is using which means that
you can just safely write frames back out to this
PcapOutputStream. Good for those applications that needs to
filter a Pcap and write out new files.out - IllegalArgumentExceptionpublic static Pcap openStream(InputStream is) throws IOException
is - IOExceptionpublic static Pcap openStream(InputStream is, int bufferCapacity) throws IOException
is - bufferCapacity - Size of buffer, must be larger than PCAPs largest framesize. See SNAPLENGTH for tcpdump, et.al.IOExceptionpublic static Pcap openStream(File file) throws FileNotFoundException, IOException
file - the pcap filePcapFileNotFoundException - in case the file doesn't exist.IOExceptionpublic static Pcap openStream(String file) throws FileNotFoundException, IOException
file - FileNotFoundExceptionIOExceptionpublic void close()
public PcapGlobalHeader getPcapHeader()
Copyright © 2021. All Rights Reserved.