Skip to content

PCAP.Filter

Andrew Lambert edited this page Nov 26, 2022 · 19 revisions

PCAP.Filter

Class Declaration

 Protected Class Filter

Remarks

This class represents a compiled filter program generated from a high level filtering expression. It is used by the driver to decide which packets will be received by a Capture.

A Capture instance may only use one filter program at a time. Changing the current filter affects all subsequently received packets, but does not affect packets already captured by the driver under the previous filter (if any).

Each instance of Filter is compiled for a specific instance of Capture. If you assign a Filter compiled for one Capture to a different Capture then the Expression is recompiled. Not all legal filtering expressions will be valid for all possible Capture instances, in which case a PCACPException will be raised with a (hopefully) useful error message explaining the incompatibility.

You cannot create an instance of Filter from an invalid or illegal filtering expression. As such, any non-Nil reference to an instance of this class is guaranteed to be a valid filter program for the Source Capture instance.

Example

This example creates a Capture that only receives TCP packets on port 80:

  Dim cap As PCAP.Capture = PCAP.BeginCapture(PCAP.GetCaptureDevice(0))
  Dim fp As PCAP.Filter = PCAP.Filter.Compile("tcp and port 80", cap)
  If fp <> Nil Then
    cap.CurrentFilter = fp
  Else
    Call MsgBox(PCAP.Filter.LastCompileError, 16, "Filter compile error")
  End If

Methods

Shared methods

Clone this wiki locally