Package pcap.spi

Interface Pcap

All Superinterfaces:
AutoCloseable

public interface Pcap
extends AutoCloseable
A handle for pcap api.
Since:
1.0.0
Author:
Ardika Rommy Sanjaya
  • Method Details

    • dumpOpen

      Dumper dumpOpen​(String file) throws ErrorException
      Open Dumper handler.
      Parameters:
      file - location of capture file will saved.
      Returns:
      returns Pcap Dumper handle.
      Throws:
      ErrorException - generic exception.
      Since:
      1.0.0
    • dumpOpenAppend

      Dumper dumpOpenAppend​(String file) throws ErrorException
      Append packet buffer on existing pcap file.
      Parameters:
      file - location of saved file.
      Returns:
      returns Pcap Dumper handle.
      Throws:
      ErrorException - generic error.
      Since:
      1.0.0
    • setFilter

      void setFilter​(String filter, boolean optimize) throws ErrorException
      BPF packet filter.
      Parameters:
      filter - filter expression.
      optimize - true for optimized filter, false otherwise.
      Throws:
      ErrorException - generic error.
      Since:
      1.0.0
    • loop

      <T> void loop​(int count, PacketHandler<T> handler, T args) throws BreakException, ErrorException
      Process packets from a live PcapLive or PcapOffline.
      Type Parameters:
      T - args type.
      Parameters:
      count - maximum number of packets to process before returning. A value of -1 or 0 for count is equivalent to infinity, so that packets are processed until another ending condition occurs.
      handler - PacketHandler callback function.
      args - user args.
      Throws:
      BreakException - breakLoop() is called.
      ErrorException - Generic error.
      Since:
      1.0.0
    • status

      Status status() throws ErrorException
      Represent packet statistics from the start of the run to the time of the call.

      Supported only on live captures, not on PcapOffline; no statistics are stored in PcapOffline so no statistics are available when reading from a PcapOffline

      Returns:
      returns Status on success.
      Throws:
      ErrorException - There is an error or if this Pcap doesn't support packet statistics.
      Since:
      1.0.0
    • breakLoop

      void breakLoop()
      Since:
      1.0.0
    • send

      void send​(ByteBuffer directBuffer, int size) throws ErrorException
      Sends a raw packet through the network interface.
      Parameters:
      directBuffer - the data of the packet, including the link-layer header.
      size - the number of bytes in the packet.
      Throws:
      ErrorException - generic error.
    • close

      void close()
      Close PcapLive or PcapOffline.
      Note: BPF handle will closed automaticly.
      Specified by:
      close in interface AutoCloseable
      Since:
      1.0.0