SharpPcap : SharpPcap.LibPcap Namespace

PcapDevice Class

Base class for all pcap devices

Syntax

public abstract class PcapDevice : SharpPcap.ICaptureDevice

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Members

See Also: Inherited members from object.

Protected Constructors

Documentation for this section has not yet been entered.

Protected Fields

captureThread System.Threading.Thread . Thread that is performing the background packet capture
m_pcapAdapterHandle IntPtr . Handle to a pcap adapter, not equal to IntPtr.Zero if an adapter is open
m_pcapIf PcapInterface . Low level interface object that contains device specific information
m_pcapPacketCount int . Number of packets that this adapter should capture
shouldCaptureThreadStop bool . Flag that indicates that a capture thread should stop

Public Properties

[read-only]
abstract
Description string . Description
Filter string . Kernel level filtering expression associated with this device. For more info on filter expression syntax, see: http://www.winpcap.org/docs/docs31/html/group__language.html
[read-only]
Interface PcapInterface . Documentation for this section has not yet been entered.
[read-only]
LastError string . The last pcap error associated with this pcap device
[read-only]
LinkType PacketDotNet.LinkLayers . Link type in terms of PacketDotNet.LinkLayers
MacAddress System.Net.NetworkInformation.PhysicalAddress . Mac address of the physical device
[read-only]
abstract
Name string . Device name
[read-only]
Opened bool . Return a value indicating if this adapter is opened
[read-only]
Started bool . Return a value indicating if the capturing process of this adapter is started
[read-only]
abstract
Statistics SharpPcap.ICaptureStatistics . Retrieves pcap statistics
StopCaptureTimeout TimeSpan . Maximum time within which the capture thread must join the main thread (on PcapDevice.StopCapture) or else the thread is aborted and an exception thrown.

Public Methods

Capture ()
Synchronously capture packets on this device. Method blocks forever.
Capture (int)
Synchronously captures packets on this network device. This method will block until capturing is finished.
static
CheckFilter (string, out string) : bool
Returns true if the filter expression was able to be compiled into a program without errors
Close ()
Closes this adapter
GetNextPacket () : SharpPcap.RawCapture
Gets the next packet captured on this device
GetNextPacket (out SharpPcap.RawCapture) : int
Gets the next packet captured on this device
GetNextPacketPointers (ref IntPtr, ref IntPtr) : int
Gets pointers to the next PCAP header and packet data. Data is only valid until next call to GetNextPacketNative. Advanced use only. Intended to allow unmanaged code to avoid the overhead of marshalling PcapHeader and packet contents to allocated memory.
abstract
Open ()
Open the device with class specific options
Open (SharpPcap.DeviceMode)
Open the device. To start capturing call the 'StartCapture' function
Open (SharpPcap.DeviceMode, int)
Open the device. To start capturing call the 'StartCapture' function
SendPacket (PacketDotNet.Packet)
Sends a raw packet throgh this device
SendPacket (byte[])
Sends a raw packet throgh this device
SendPacket (PacketDotNet.Packet, int)
Sends a raw packet throgh this device
SendPacket (byte[], int)
Sends a raw packet throgh this device
StartCapture ()
Starts the capturing process via a background thread OnPacketArrival() will be called for each captured packet
StopCapture ()
Stops the capture process Throws an exception if the stop capture timeout is exceeded and the capture thread was aborted
override
ToString () : string
Override the default ToString() implementation

Protected Methods

CaptureThread ()
The capture thread
MarshalRawPacket (IntPtr, IntPtr) : SharpPcap.RawCapture
Convert an unmanaged packet into a managed PacketDotNet.RawPacket
PacketHandler (IntPtr, IntPtr, IntPtr)
Pcap_loop callback method.
SendCaptureStoppedEvent (SharpPcap.CaptureStoppedEventStatus)
Notify the delegates that are subscribed to the capture stopped event
SendPacketArrivalEvent (SharpPcap.RawCapture)
Notify the OnPacketArrival delegates about a newly captured packet
SetFilter (string)
Assign a filter to this device given a filterExpression
ThrowIfNotOpen (string)
Helper method for checking that the adapter is open, throws an exception with a string of ExceptionString if the device isn't open

Public Events

OnCaptureStopped Fired when the capture process of this pcap device is stopped
OnPacketArrival Fires whenever a new packet is processed, either when the packet arrives from the network device or when the packet is read from the on-disk file. For network captured packets this event is invoked only when working in "PcapMode.Capture" mode.

Member Details

PcapDevice Constructor

Documentation for this section has not yet been entered.

Syntax

protected PcapDevice ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Capture Method

Synchronously capture packets on this device. Method blocks forever.

Syntax

public void Capture ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Capture Method

Synchronously captures packets on this network device. This method will block until capturing is finished.

Syntax

public void Capture (int packetCount)

Parameters

packetCount
The number of packets to be captured. -1 means capture indefiniately

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

captureThread Field

Thread that is performing the background packet capture

Syntax

protected System.Threading.Thread captureThread

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

CaptureThread Method

The capture thread

Syntax

protected virtual void CaptureThread ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

CheckFilter Method

Returns true if the filter expression was able to be compiled into a program without errors

Syntax

public static bool CheckFilter (string filterExpression, out string errorString)

Parameters

filterExpression
Documentation for this section has not yet been entered.
errorString
Documentation for this section has not yet been entered.

Returns

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Close Method

Closes this adapter

Syntax

public virtual void Close ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Description Property

Description

Syntax

public abstract string Description { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Filter Property

Kernel level filtering expression associated with this device. For more info on filter expression syntax, see: http://www.winpcap.org/docs/docs31/html/group__language.html

Syntax

public virtual string Filter { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

GetNextPacket Method

Gets the next packet captured on this device

Syntax

public virtual SharpPcap.RawCapture GetNextPacket ()

Returns

The next packet captured on this device

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

GetNextPacket Method

Gets the next packet captured on this device

Syntax

public virtual int GetNextPacket (out SharpPcap.RawCapture p)

Parameters

p
A SharpPcap.RawCapture

Returns

A int that contains the result code

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

GetNextPacketPointers Method

Gets pointers to the next PCAP header and packet data. Data is only valid until next call to GetNextPacketNative. Advanced use only. Intended to allow unmanaged code to avoid the overhead of marshalling PcapHeader and packet contents to allocated memory.

Syntax

public int GetNextPacketPointers (ref IntPtr header, ref IntPtr data)

Parameters

header
Documentation for this section has not yet been entered.
data
Documentation for this section has not yet been entered.

Returns

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Interface Property

Documentation for this section has not yet been entered.

Syntax

public PcapInterface Interface { get; }

Value

Low level pcap device values

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

LastError Property

The last pcap error associated with this pcap device

Syntax

public virtual string LastError { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

LinkType Property

Link type in terms of PacketDotNet.LinkLayers

Syntax

public virtual PacketDotNet.LinkLayers LinkType { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

m_pcapAdapterHandle Field

Handle to a pcap adapter, not equal to IntPtr.Zero if an adapter is open

Syntax

protected IntPtr m_pcapAdapterHandle

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

m_pcapIf Field

Low level interface object that contains device specific information

Syntax

protected PcapInterface m_pcapIf

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

m_pcapPacketCount Field

Number of packets that this adapter should capture

Syntax

protected int m_pcapPacketCount

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

MacAddress Property

Mac address of the physical device

Syntax

public virtual System.Net.NetworkInformation.PhysicalAddress MacAddress { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

MarshalRawPacket Method

Convert an unmanaged packet into a managed PacketDotNet.RawPacket

Syntax

protected virtual SharpPcap.RawCapture MarshalRawPacket (IntPtr header, IntPtr data)

Parameters

header
A IntPtr
data
A IntPtr

Returns

A SharpPcap.RawCapture

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Name Property

Device name

Syntax

public abstract string Name { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

OnCaptureStopped Event

Fired when the capture process of this pcap device is stopped

Syntax

public event SharpPcap.CaptureStoppedEventHandler OnCaptureStopped

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

OnPacketArrival Event

Fires whenever a new packet is processed, either when the packet arrives from the network device or when the packet is read from the on-disk file. For network captured packets this event is invoked only when working in "PcapMode.Capture" mode.

Syntax

public event SharpPcap.PacketArrivalEventHandler OnPacketArrival

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Open Method

Open the device with class specific options

Syntax

public abstract void Open ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Open Method

Open the device. To start capturing call the 'StartCapture' function

Syntax

public virtual void Open (SharpPcap.DeviceMode mode)

Parameters

mode
A SharpPcap.DeviceMode

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Open Method

Open the device. To start capturing call the 'StartCapture' function

Syntax

public virtual void Open (SharpPcap.DeviceMode mode, int read_timeout)

Parameters

mode
A SharpPcap.DeviceMode
read_timeout
A int

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Opened Property

Return a value indicating if this adapter is opened

Syntax

public virtual bool Opened { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

PacketHandler Method

Pcap_loop callback method.

Syntax

protected virtual void PacketHandler (IntPtr param, IntPtr header, IntPtr data)

Parameters

param
Documentation for this section has not yet been entered.
header
Documentation for this section has not yet been entered.
data
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SendCaptureStoppedEvent Method

Notify the delegates that are subscribed to the capture stopped event

Syntax

protected void SendCaptureStoppedEvent (SharpPcap.CaptureStoppedEventStatus status)

Parameters

status
A SharpPcap.CaptureStoppedEventStatus

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SendPacket Method

Sends a raw packet throgh this device

Syntax

public virtual void SendPacket (PacketDotNet.Packet p)

Parameters

p
The packet to send

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SendPacket Method

Sends a raw packet throgh this device

Syntax

public virtual void SendPacket (byte[] p)

Parameters

p
The packet bytes to send

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SendPacket Method

Sends a raw packet throgh this device

Syntax

public virtual void SendPacket (PacketDotNet.Packet p, int size)

Parameters

p
The packet to send
size
The number of bytes to send

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SendPacket Method

Sends a raw packet throgh this device

Syntax

public virtual void SendPacket (byte[] p, int size)

Parameters

p
The packet bytes to send
size
The number of bytes to send

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SendPacketArrivalEvent Method

Notify the OnPacketArrival delegates about a newly captured packet

Syntax

protected virtual void SendPacketArrivalEvent (SharpPcap.RawCapture p)

Parameters

p
A SharpPcap.RawCapture

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

SetFilter Method

Assign a filter to this device given a filterExpression

Syntax

protected void SetFilter (string filterExpression)

Parameters

filterExpression
The filter expression to compile

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

shouldCaptureThreadStop Field

Flag that indicates that a capture thread should stop

Syntax

protected bool shouldCaptureThreadStop

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

StartCapture Method

Starts the capturing process via a background thread OnPacketArrival() will be called for each captured packet

Syntax

public virtual void StartCapture ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Started Property

Return a value indicating if the capturing process of this adapter is started

Syntax

public virtual bool Started { get; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

Statistics Property

Retrieves pcap statistics

Syntax

public abstract SharpPcap.ICaptureStatistics Statistics { get; }

Value

A SharpPcap.LibPcap.PcapStatistics

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

StopCapture Method

Stops the capture process Throws an exception if the stop capture timeout is exceeded and the capture thread was aborted

Syntax

public virtual void StopCapture ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

StopCaptureTimeout Property

Maximum time within which the capture thread must join the main thread (on PcapDevice.StopCapture) or else the thread is aborted and an exception thrown.

Syntax

public TimeSpan StopCaptureTimeout { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

ThrowIfNotOpen Method

Helper method for checking that the adapter is open, throws an exception with a string of ExceptionString if the device isn't open

Syntax

protected void ThrowIfNotOpen (string ExceptionString)

Parameters

ExceptionString
A string

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0

ToString Method

Override the default ToString() implementation

Syntax

public override string ToString ()

Returns

A string

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: SharpPcap.LibPcap
Assembly: SharpPcap (in SharpPcap.dll)
Assembly Versions: 4.0.1.0