Class BpfProgram


  • public final class BpfProgram
    extends java.lang.Object
    Since:
    pcap4j 0.9.16
    Author:
    Kaito Yamada
    • Method Summary

      Modifier and Type Method Description
      boolean applyFilter​(byte[] packet)
      Apply the filter on a given packet.
      boolean applyFilter​(byte[] packet, int orgPacketLen, int packetLen)
      Apply the filter on a given packet.
      boolean applyFilter​(Packet packet)
      Apply the filter on a given packet.
      void free()
      Releases the resource this object holds in the native memory.
      java.lang.String getExpression()  
      boolean isFreed()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getExpression

        public java.lang.String getExpression()
        Returns:
        expression
      • applyFilter

        public boolean applyFilter​(Packet packet)
        Apply the filter on a given packet. Return true if the packet given passes the filter that is built from this program.
        Parameters:
        packet - the packet to apply the filter on
        Returns:
        true if this program is not freed and the packet passes the filter; false otherwise.
      • applyFilter

        public boolean applyFilter​(byte[] packet)
        Apply the filter on a given packet. Return true if the packet given passes the filter that is built from this program.
        Parameters:
        packet - the packet to apply the filter on
        Returns:
        true if this program is not freed and the packet passes the filter; false otherwise.
      • applyFilter

        public boolean applyFilter​(byte[] packet,
                                   int orgPacketLen,
                                   int packetLen)
        Apply the filter on a given packet. Return true if the packet given passes the filter that is built from this program.
        Parameters:
        packet - a byte array including the packet to apply the filter on
        orgPacketLen - the length of the original packet
        packetLen - the length of the packet present
        Returns:
        true if this program is not freed and the packet passes the filter; false otherwise.
      • isFreed

        public boolean isFreed()
        Returns:
        true if the bpf_program represented by this object is freed; false otherwise.
      • free

        public void free()
        Releases the resource this object holds in the native memory. This method takes effect only at the first call, and does nothing at later calls. It's required to call this method before this object is GCed in order to avoid memory leak.