Skip to content

Commit db3c053

Browse files
Merge pull request #20 from Lansweeper/feat/add-clone-to-LibPcapLiveDevice
feat: add clone for LibPcapLiveDevice
2 parents 99fa584 + bbc71d2 commit db3c053

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

SharpPcap/LibPcap/ILibPcapLiveDevice.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public interface ILibPcapLiveDevice : ILiveDevice
4141
/// </summary>
4242
PcapHandle Handle { get; }
4343

44+
/// <summary>
45+
/// Returns a clone of the current device.
46+
/// This clone can then be opened and used to capture packets independently of the original device.
47+
/// You can set the <see cref="Filter"/> without interfering with the original.
48+
/// </summary>
49+
/// <param name="device">The original device</param>
50+
/// <returns>The cloned device</returns>
51+
ILibPcapLiveDevice Clone();
52+
53+
4454
/// <summary>
4555
/// Override the default ToString() implementation
4656
/// </summary>
@@ -68,6 +78,5 @@ public interface ILibPcapLiveDevice : ILiveDevice
6878
/// See https://www.tcpdump.org/manpages/pcap_next_ex.3pcap.html
6979
/// </returns>
7080
int GetNextPacketPointers(ref IntPtr header, ref IntPtr data);
71-
7281
}
7382
}

SharpPcap/LibPcap/LibPcapLiveDevice.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System;
88
using System.Collections.ObjectModel;
99
using System.Runtime.InteropServices;
10-
using System.Text;
1110

1211
namespace SharpPcap.LibPcap
1312
{
@@ -33,6 +32,12 @@ protected LibPcapLiveDevice()
3332
{
3433
}
3534

35+
/// <inheritdoc/>
36+
public ILibPcapLiveDevice Clone()
37+
{
38+
return new LibPcapLiveDevice(Interface);
39+
}
40+
3641
/// <summary>
3742
/// PcapDevice finalizer. Ensure PcapDevices are stopped and closed before exit.
3843
/// </summary>

SharpPcap/SharpPcap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SPDX-License-Identifier: MIT
88
<Project Sdk="Microsoft.NET.Sdk">
99
<PropertyGroup>
1010
<TargetFramework>net8.0</TargetFramework>
11-
<Version>10.0.0-beta.1</Version> <!--update manually, this is in sync with the Lansweeper On-Prem version-->
11+
<Version>10.0.0-beta.2</Version> <!--update manually, this is in sync with the Lansweeper On-Prem version-->
1212
<PackageId>Lansweeper.SharpPcap</PackageId>
1313
<Company>Lansweeper</Company>
1414
<Title>Lansweeper SharpPcap</Title>

0 commit comments

Comments
 (0)