From 0c86b45a189a1fdf4a27bba30ce3f9aadfaa6ab5 Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 09:19:14 +0200
Subject: [PATCH 01/53] Update config.yml
---
.circleci/config.yml | 192 +++++++++++++++++++++++++++++++++----------
1 file changed, 150 insertions(+), 42 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 8e31d55e..365c4942 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -1,55 +1,163 @@
version: 2.1
+parameters:
+ csproj-file:
+ type: string
+ default: "SharpPcap/SharpPcap.csproj"
+ sonar-project:
+ type: string
+ default: "Lansweeper_SharpPcap"
+ nuget-output-file:
+ type: string
+ default: "bin/Release/netstandard2.0/SharpPcap.nupkg"
+
+executors:
+ node:
+ docker:
+ - image: circleci/node:12
+
orbs:
- win: circleci/windows@2.4.1
+ win: circleci/windows@2.2.0
+ sonar-check: lansweeper/sonar@0.0.6
jobs:
- test-windows:
+ build:
+ executor: win/default
+
+ steps:
+ - checkout
+ - run:
+ name: Install SonarScanner for MSBuild .NET Core Global Tool
+ command: dotnet tool install --global dotnet-sonarscanner
+ - run:
+ name: Start SonarScanner
+ command: dotnet sonarscanner begin /k:"<< pipeline.parameters.sonar-project >>" /d:sonar.verbose=true /o:"lansweeper" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=$Env:SONAR_TOKEN /d:sonar.language="cs"
+ - run: dotnet build << pipeline.parameters.csproj-file >> --configuration Release
+ - run:
+ name: Upload SonarScanner results
+ command: dotnet sonarscanner end /d:sonar.login=$Env:SONAR_TOKEN
+
+ - persist_to_workspace:
+ root: .
+ paths:
+ - .
+
+ nuget-prepare:
executor:
name: win/default
steps:
- - checkout
- - run: dotnet build -c Release
- - run: bash scripts/test.sh --filter "TestCategory=WinDivert"
-
- test-ubuntu:
- parameters:
- ubuntu:
- description: Ubuntu version
- type: string
- libpcap:
- description: How to install libpcap
- type: string
- machine:
- image: << parameters.ubuntu >>:202010-01
+ - run:
+ name: Create local nuget config file
+ command: |
+ $xml = "
+
+
+
+
+
+
+
+
+
+
+ "
+ Out-File -FilePath nuget.config -InputObject $xml -Encoding ASCII
+ - run: type nuget.config
+ - persist_to_workspace:
+ root: .
+ paths:
+ - .
+
+ nuget-publish:
+ executor:
+ name: win/default
steps:
- - checkout
- - run: sudo -E bash scripts/install-dotnet.sh
- - run: sudo -E bash scripts/install-tap.sh
- # Download and compile latest libpcap
- - when:
- condition: { equal: [ libpcap-script, << parameters.libpcap >> ] }
- steps:
- - run: sudo -E bash scripts/install-libpcap.sh
- # Install libpcap from apt-get
- - when:
- condition: {not: { equal: [ libpcap-script, << parameters.libpcap >> ] } }
- steps:
- - run: sudo apt-get install << parameters.libpcap >>
- - run: sudo -E bash scripts/test.sh --filter TestCategory!=SendPacket
- - store_test_results:
- path: Test/TestResults
- - store_artifacts:
- path: Test/TestResults
+ - attach_workspace:
+ at: .
+ - run:
+ name: Set correct version in csproj file, build and pack it
+ command: |
+ $env:package_version = "9.0.0"
+
+ $file = Get-Item << pipeline.parameters.csproj-file >>
+ [xml]$cn = Get-Content $file
+ $cn.Project.PropertyGroup.Version="$env:package_version"
+ $cn.Save($file.FullName)
+ type ./<< pipeline.parameters.csproj-file >>
+ - run:
+ name: Pack the package
+ command: dotnet pack << pipeline.parameters.csproj-file >> --configuration Release
+ - run:
+ name: Publish the package
+ command: |
+ dotnet nuget push << pipeline.parameters.nuget-output-file >> --source "github" --api-key $env:GITHUB_TOKEN
+
+ sonar:
+ executor: node
+ steps:
+ - attach_workspace:
+ at: .
+ - sonar-check/get_sonar_status:
+ report_file: "/home/circleci/project/.sonarqube/out/.sonar/report-task.txt"
workflows:
version: 2
- build:
+
+ ci_on_pr:
+ jobs:
+ - build:
+ context:
+ - lec-github-packages-rw
+ - SonarCloud
+ filters:
+ branches:
+ ignore: master
+
+ - sonar:
+ context:
+ - SonarCloud
+ requires:
+ - build
+ filters:
+ branches:
+ ignore: master
+
+ ci_and_release_master:
+ jobs:
+ - build:
+ context:
+ - lec-github-packages-rw
+ - SonarCloud
+ filters:
+ branches:
+ only: master
+ - nuget-prepare:
+ requires:
+ - build
+ context:
+ - lec-github-packages-rw
+ filters:
+ branches:
+ only: master
+ - nuget-publish:
+ requires:
+ - nuget-prepare
+ context:
+ - lec-github-packages-rw
+ filters:
+ branches:
+ only: master
+
+ run-daily-tests:
+ triggers:
+ - schedule:
+ cron: "0 0 * * *"
+ filters:
+ branches:
+ only: master
+
jobs:
- - test-windows
- - test-ubuntu:
- name: << matrix.ubuntu >>-<< matrix.libpcap >>
- matrix:
- parameters:
- ubuntu: [ "ubuntu-1604", "ubuntu-2004" ]
- libpcap: [ "libpcap-script", "libpcap-dev", "libpcap0.8" ]
+ - build:
+ context:
+ - lec-github-packages-rw
+ - SonarCloud
From a2dde4ea9e49b762d0da31a6a2d1a1c7b11cc675 Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 09:24:41 +0200
Subject: [PATCH 02/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 365c4942..7c84e526 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -6,7 +6,7 @@ parameters:
default: "SharpPcap/SharpPcap.csproj"
sonar-project:
type: string
- default: "Lansweeper_SharpPcap"
+ default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
default: "bin/Release/netstandard2.0/SharpPcap.nupkg"
From 072f2c804c01e96ecc2a17c4d9eab2a42d01eff1 Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 09:29:54 +0200
Subject: [PATCH 03/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 7c84e526..23a4336b 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "bin/Release/netstandard2.0/SharpPcap.nupkg"
+ default: "bin/Release/SharpPcap.nupkg"
executors:
node:
From 062f27222055175db836237765d934b6e4b22e7b Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 09:36:51 +0200
Subject: [PATCH 04/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 23a4336b..3af52f9c 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "bin/Release/SharpPcap.nupkg"
+ default: "bin/Release/SharpPcap.9.0.0.nupkg"
executors:
node:
From 3441a56b2c8c51bd81397411a1371d76bb69152e Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 09:41:55 +0200
Subject: [PATCH 05/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 3af52f9c..4765f9cf 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "bin/Release/SharpPcap.9.0.0.nupkg"
+ default: "SharpPcap/bin/Release/SharpPcap.9.0.0.nupkg"
executors:
node:
From 05d726874c9e40051a6e1e687f1a8c9c6b92b1ca Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 09:48:46 +0200
Subject: [PATCH 06/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 4765f9cf..cea42ab5 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -56,7 +56,7 @@ jobs:
-
+
From a1dab8c336ddac9f373e93941b9af23a0ba10355 Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 10:08:07 +0200
Subject: [PATCH 07/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index cea42ab5..22e64d17 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -56,7 +56,7 @@ jobs:
-
+
From 24f8b8c4c998c5dfc98a2ba24f435526e435d2ac Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 10:18:35 +0200
Subject: [PATCH 08/53] Update SharpPcap.csproj
---
SharpPcap/SharpPcap.csproj | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 87205abd..7475d47f 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -1,12 +1,12 @@
netstandard2.0
- 6.2.0
+ 9.0.0
A packet capture framework for .NET
Tamir Gal, Chris Morgan and others
https://github.com/chmorgan/sharppcap
false
- https://github.com/chmorgan/sharppcap
+ https://github.com/Lansweeper/SnmpSharpNet
true
true
true
From 911d738a87ded324f02b775683c7d235737249dd Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 10:35:44 +0200
Subject: [PATCH 09/53] Update SharpPcap.csproj
---
SharpPcap/SharpPcap.csproj | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 7475d47f..ac5608bc 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -2,6 +2,10 @@
netstandard2.0
9.0.0
+ Lansweeper.SharpPcap
+ Lansweeper
+ Lansweeper SharpPcap
+ Lansweeper SharpPcap
A packet capture framework for .NET
Tamir Gal, Chris Morgan and others
https://github.com/chmorgan/sharppcap
From 2d4b606be21e6fcbda01ac4dc06f5a00c8d89954 Mon Sep 17 00:00:00 2001
From: KoenPlasmansLS <71259874+KoenPlasmansLS@users.noreply.github.com>
Date: Sat, 7 May 2022 10:36:14 +0200
Subject: [PATCH 10/53] Update config.yml
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 22e64d17..f7969b36 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/SharpPcap.9.0.0.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.0.nupkg"
executors:
node:
From ad7a28a28dc3206f01146214d8840d94e61f300f Mon Sep 17 00:00:00 2001
From: KoenPlasmans
Date: Mon, 9 May 2022 10:16:59 +0200
Subject: [PATCH 11/53] Use suggested fix
---
.circleci/config.yml | 4 ++--
SharpPcap/LibPcap/PcapDevice.cs | 7 ++++++-
SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs | 11 ++++++++---
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 711238a9..7f027d2b 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.0.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.1.nupkg"
executors:
node:
@@ -77,7 +77,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.0"
+ $env:package_version = "9.0.1"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
diff --git a/SharpPcap/LibPcap/PcapDevice.cs b/SharpPcap/LibPcap/PcapDevice.cs
index 2176148d..1e69ec7f 100644
--- a/SharpPcap/LibPcap/PcapDevice.cs
+++ b/SharpPcap/LibPcap/PcapDevice.cs
@@ -277,9 +277,14 @@ public int GetNextPacketPointers(ref IntPtr header, ref IntPtr data)
///
/// Pcap_loop callback method.
///
- protected virtual void PacketHandler(IntPtr param, IntPtr /* pcap_pkthdr* */ header, IntPtr data)
+ protected virtual void PacketHandler(IntPtr handlePtr, IntPtr /* pcap_pkthdr* */ header, IntPtr data)
{
var handle = Handle;
+ if (handle.DangerousGetHandle() != handlePtr)
+ {
+ // The handle changed, we are being called from a soon to be dead thread.
+ return;
+ }
var gotRef = false;
try
{
diff --git a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
index 052b9163..d0d5d505 100644
--- a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
+++ b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
@@ -21,6 +21,7 @@ You should have received a copy of the GNU Lesser General Public License
*/
using System;
+using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
@@ -165,7 +166,7 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
continue;
}
- int res = LibPcapSafeNativeMethods.pcap_dispatch(Handle, m_pcapPacketCount, Callback, IntPtr.Zero);
+ int res = LibPcapSafeNativeMethods.pcap_dispatch(Handle, m_pcapPacketCount, Callback, Handle.DangerousGetHandle());
// pcap_dispatch() returns the number of packets read or, a status value if the value
// is negative
@@ -192,8 +193,12 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
case Pcap.LOOP_EXIT_WITH_ERROR: // An error occurred whilst capturing.
SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
return;
- default: // This can only be triggered by a bug in libpcap.
- throw new PcapException("Unknown pcap_loop exit status.");
+ default:
+ // This can only be triggered by a bug in libpcap.
+ // We can't throw here, sicne that would crash the application
+ Trace.TraceError($"SharpPcap: Unknown pcap_loop exit status: {res}");
+ SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
+ return;
}
}
else // res > 0
From c283a5eecbfd9bad6a0017c9d0e95b7658bf8dd0 Mon Sep 17 00:00:00 2001
From: KoenPlasmans
Date: Mon, 9 May 2022 10:24:34 +0200
Subject: [PATCH 12/53] Aha
---
SharpPcap/SharpPcap.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 2e7cea79..b49260dd 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -1,7 +1,7 @@
netstandard2.0
- 9.0.0
+ 9.0.1
Lansweeper.SharpPcap
Lansweeper
Lansweeper SharpPcap
From 4eff4feaefa4e122cdb10c4c252a6a092ea18cfa Mon Sep 17 00:00:00 2001
From: KoenPlasmans
Date: Mon, 9 May 2022 10:29:36 +0200
Subject: [PATCH 13/53] double
---
SharpPcap/SharpPcap.csproj | 1 -
1 file changed, 1 deletion(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index b49260dd..6db4a251 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -6,7 +6,6 @@
Lansweeper
Lansweeper SharpPcap
Lansweeper SharpPcap
- 6.2.1
A packet capture framework for .NET
Tamir Gal, Chris Morgan and others
https://github.com/chmorgan/sharppcap
From 462d99288cf7e54bb9a597d0886a07e3ae6cb233 Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Tue, 23 Aug 2022 14:56:02 +0200
Subject: [PATCH 14/53] feat: extract and expand interface + fix test
---
SharpPcap/LibPcap/ILibPcapLiveDevice.cs | 73 +++++++++++++++++++++++++
SharpPcap/LibPcap/LibPcapLiveDevice.cs | 2 +-
Test/CaptureFileReaderDeviceTest.cs | 3 +
3 files changed, 77 insertions(+), 1 deletion(-)
create mode 100644 SharpPcap/LibPcap/ILibPcapLiveDevice.cs
diff --git a/SharpPcap/LibPcap/ILibPcapLiveDevice.cs b/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
new file mode 100644
index 00000000..921aeaf0
--- /dev/null
+++ b/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.ObjectModel;
+
+namespace SharpPcap.LibPcap
+{
+ public interface ILibPcapLiveDevice : ILiveDevice
+ {
+
+ ///
+ /// Addresses that represent this device
+ ///
+ ReadOnlyCollection Addresses { get; }
+
+ ///
+ /// Interface flags, see pcap_findalldevs() man page for more info
+ ///
+ uint Flags { get; }
+
+ ///
+ /// True if device is a loopback interface, false if not
+ ///
+ bool Loopback { get; }
+
+ ///
+ /// Set/Get Non-Blocking Mode. returns allways false for savefiles.
+ ///
+ bool NonBlockingMode { get; set; }
+
+ ///
+ /// Low level pcap device values
+ ///
+ PcapInterface Interface { get; }
+
+ ///
+ /// Return a value indicating if this adapter is opened
+ ///
+ bool Opened { get; }
+
+ ///
+ /// The underlying pcap device handle
+ ///
+ PcapHandle Handle { get; }
+
+ ///
+ /// Override the default ToString() implementation
+ ///
+ ///
+ /// A
+ ///
+ string ToString();
+
+ ///
+ /// Synchronously captures packets on this network device. This method will block
+ /// until capturing is finished.
+ ///
+ /// The number of packets to be captured.
+ /// -1 means capture indefiniately
+ void Capture(int packetCount);
+
+ ///
+ /// 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.
+ ///
+ ///
+ /// See https://www.tcpdump.org/manpages/pcap_next_ex.3pcap.html
+ ///
+ int GetNextPacketPointers(ref IntPtr header, ref IntPtr data);
+
+ }
+}
\ No newline at end of file
diff --git a/SharpPcap/LibPcap/LibPcapLiveDevice.cs b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
index 1bf77472..7c4a5802 100644
--- a/SharpPcap/LibPcap/LibPcapLiveDevice.cs
+++ b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
@@ -30,7 +30,7 @@ namespace SharpPcap.LibPcap
///
/// Capture live packets from a network device
///
- public class LibPcapLiveDevice : PcapDevice, ILiveDevice
+ public class LibPcapLiveDevice : PcapDevice, ILibPcapLiveDevice
{
///
/// Constructs a new PcapDevice based on a 'pcapIf' struct
diff --git a/Test/CaptureFileReaderDeviceTest.cs b/Test/CaptureFileReaderDeviceTest.cs
index a648b232..3127ef71 100644
--- a/Test/CaptureFileReaderDeviceTest.cs
+++ b/Test/CaptureFileReaderDeviceTest.cs
@@ -5,6 +5,8 @@
using PacketDotNet;
using System.IO;
using System.Collections.Generic;
+using System.Globalization;
+using System.Threading;
namespace Test
{
@@ -28,6 +30,7 @@ public void CaptureNonExistant()
[TestCase(TimestampResolution.Microsecond, "1186341404.189852s")]
public void CaptureTimestampResolution(TimestampResolution resolution, string timeval)
{
+ Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
var filename = "ipv6_http.pcap";
using var device = new CaptureFileReaderDevice(TestHelper.GetFile(filename));
var configuration = new DeviceConfiguration
From 8de70d8cbb38dd53a44a1b48ce2003e2055ea346 Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Tue, 23 Aug 2022 15:14:45 +0200
Subject: [PATCH 15/53] feat: changed version for nuget
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 7f027d2b..0b6e93b3 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.1.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.2.nupkg"
executors:
node:
@@ -77,7 +77,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.1"
+ $env:package_version = "9.0.2"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From 3f107666311dcffda61480d9a9010977d513feff Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Tue, 23 Aug 2022 15:50:18 +0200
Subject: [PATCH 16/53] feat: extracted interface
---
SharpPcap/LibPcap/IPcapInterface.cs | 63 +++++++++++++++++++++++++++++
SharpPcap/LibPcap/PcapInterface.cs | 2 +-
2 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 SharpPcap/LibPcap/IPcapInterface.cs
diff --git a/SharpPcap/LibPcap/IPcapInterface.cs b/SharpPcap/LibPcap/IPcapInterface.cs
new file mode 100644
index 00000000..1db5e5d0
--- /dev/null
+++ b/SharpPcap/LibPcap/IPcapInterface.cs
@@ -0,0 +1,63 @@
+using System.Collections.Generic;
+using System.Net;
+using System.Net.NetworkInformation;
+
+namespace SharpPcap.LibPcap
+{
+ public interface IPcapInterface
+ {
+ ///
+ /// Name of the interface. Used internally when passed to pcap_open_live()
+ ///
+ string Name { get; }
+
+ ///
+ /// Human readable interface name derived from System.Net.NetworkInformation.NetworkInterface.Name
+ ///
+ string FriendlyName { get; }
+
+ ///
+ /// Text description of the interface as given by pcap/npcap
+ ///
+ string Description { get; }
+
+ ///
+ /// Gateway address of this device
+ /// NOTE: May only be available on Windows
+ ///
+ List GatewayAddresses { get; }
+
+ ///
+ /// Addresses associated with this device
+ ///
+ List Addresses { get; }
+
+ ///
+ /// Pcap interface flags
+ ///
+ uint Flags { get; }
+
+ ///
+ /// MacAddress of the interface
+ ///
+ PhysicalAddress MacAddress { get; }
+
+ ///
+ /// Timestamps supported by this device
+ ///
+ ///
+ ///
+ /// Note: Live devices can have supported timestamps but offline devices
+ /// (such as file readers etc) do not. See https://www.tcpdump.org/manpages/pcap-tstamp.7.html
+ ///
+ System.Collections.Generic.List TimestampsSupported { get; }
+
+ ///
+ /// ToString override
+ ///
+ ///
+ /// A
+ ///
+ string ToString();
+ }
+}
\ No newline at end of file
diff --git a/SharpPcap/LibPcap/PcapInterface.cs b/SharpPcap/LibPcap/PcapInterface.cs
index 0fd19d7d..93ce1f36 100644
--- a/SharpPcap/LibPcap/PcapInterface.cs
+++ b/SharpPcap/LibPcap/PcapInterface.cs
@@ -36,7 +36,7 @@ namespace SharpPcap.LibPcap
/// device memory is freed, so instead convert the unmanaged structure
/// to a managed one to avoid this issue
///
- public class PcapInterface
+ public class PcapInterface : IPcapInterface
{
///
/// Name of the interface. Used internally when passed to pcap_open_live()
From c677b2472a751bbe9a478e15e0bda70cf38e9d0f Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Tue, 23 Aug 2022 15:53:59 +0200
Subject: [PATCH 17/53] feat: added info to readme and changed version in
config
---
.circleci/config.yml | 4 ++--
README.md | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 0b6e93b3..7cde5f47 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.2.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.3.nupkg"
executors:
node:
@@ -77,7 +77,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.2"
+ $env:package_version = "9.0.3"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
diff --git a/README.md b/README.md
index 94ca4817..0628e90d 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,16 @@ For packet dissection and creation see [Packet.Net](https://github.com/chmorgan/
* .NET Core 3 and .NET Framework support
+# Publishing to nuget package
+Change the following lines in the config.yml file to automatically trigger a publish of the nuget package:
+
+Change the version here =>
+ nuget-output-file:
+ type: string
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.*.*.*.nupkg"
+And here =>
+ $env:package_version = "*.*.*"
# Examples
See the [Examples](https://github.com/chmorgan/sharppcap/tree/master/Examples) folder for a range of full example projects using SharpPcap
From 2276fbfc559e9f1b14e81cd7333970bfd5b08a57 Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Tue, 23 Aug 2022 16:27:04 +0200
Subject: [PATCH 18/53] feat: extracted interface + version change
---
.circleci/config.yml | 4 ++--
SharpPcap/LibPcap/IPcapAddress.cs | 33 +++++++++++++++++++++++++++++++
SharpPcap/LibPcap/PcapAddress.cs | 2 +-
3 files changed, 36 insertions(+), 3 deletions(-)
create mode 100644 SharpPcap/LibPcap/IPcapAddress.cs
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 7cde5f47..5aa06e25 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.3.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.4.nupkg"
executors:
node:
@@ -77,7 +77,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.3"
+ $env:package_version = "9.0.4"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
diff --git a/SharpPcap/LibPcap/IPcapAddress.cs b/SharpPcap/LibPcap/IPcapAddress.cs
new file mode 100644
index 00000000..a85d57c7
--- /dev/null
+++ b/SharpPcap/LibPcap/IPcapAddress.cs
@@ -0,0 +1,33 @@
+namespace SharpPcap.LibPcap
+{
+ public interface IPcapAddress
+ {
+ ///
+ /// The address value of this PcapAddress, null if none is present
+ ///
+ Sockaddr Addr { get; }
+
+ ///
+ /// Netmask of this PcapAddress, null if none is present
+ ///
+ Sockaddr Netmask { get; }
+
+ ///
+ /// Broadcast address of this PcapAddress, null if none is present
+ ///
+ Sockaddr Broadaddr { get; }
+
+ ///
+ /// Destination address, null if the interface isn't a point-to-point interface
+ ///
+ Sockaddr Dstaddr { get; }
+
+ ///
+ /// ToString override
+ ///
+ ///
+ /// A
+ ///
+ string ToString();
+ }
+}
\ No newline at end of file
diff --git a/SharpPcap/LibPcap/PcapAddress.cs b/SharpPcap/LibPcap/PcapAddress.cs
index 6024ab4e..3c10242e 100755
--- a/SharpPcap/LibPcap/PcapAddress.cs
+++ b/SharpPcap/LibPcap/PcapAddress.cs
@@ -27,7 +27,7 @@ namespace SharpPcap.LibPcap
///
/// Managed representation of the unmanaged pcap_addr structure
///
- public class PcapAddress
+ public class PcapAddress : IPcapAddress
{
///
/// The address value of this PcapAddress, null if none is present
From 57a69bfed141add575b6e3443211761cdda33440 Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Wed, 24 Aug 2022 10:35:32 +0200
Subject: [PATCH 19/53] feat: resolve interface issues
---
SharpPcap/ARP.cs | 2 +-
SharpPcap/LibPcap/ILibPcapLiveDevice.cs | 2 +-
SharpPcap/LibPcap/IPcapInterface.cs | 9 ++++++--
SharpPcap/LibPcap/LibPcapLiveDevice.cs | 2 +-
SharpPcap/LibPcap/PcapDevice.cs | 27 ++++++------------------
SharpPcap/LibPcap/PcapInterface.cs | 12 ++++++-----
SharpPcap/Statistics/StatisticsDevice.cs | 2 +-
Test/MemorySafetyTests.cs | 2 +-
8 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/SharpPcap/ARP.cs b/SharpPcap/ARP.cs
index 8d8a35c3..3f08fe94 100644
--- a/SharpPcap/ARP.cs
+++ b/SharpPcap/ARP.cs
@@ -30,7 +30,7 @@ namespace SharpPcap
///
public class ARP
{
- private readonly PcapInterface pcapInterface;
+ private readonly IPcapInterface pcapInterface;
///
/// Constructs a new ARP Resolver
diff --git a/SharpPcap/LibPcap/ILibPcapLiveDevice.cs b/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
index 921aeaf0..864c70ee 100644
--- a/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
+++ b/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
@@ -29,7 +29,7 @@ public interface ILibPcapLiveDevice : ILiveDevice
///
/// Low level pcap device values
///
- PcapInterface Interface { get; }
+ IPcapInterface Interface { get; }
///
/// Return a value indicating if this adapter is opened
diff --git a/SharpPcap/LibPcap/IPcapInterface.cs b/SharpPcap/LibPcap/IPcapInterface.cs
index 1db5e5d0..7c4662c5 100644
--- a/SharpPcap/LibPcap/IPcapInterface.cs
+++ b/SharpPcap/LibPcap/IPcapInterface.cs
@@ -30,12 +30,12 @@ public interface IPcapInterface
///
/// Addresses associated with this device
///
- List Addresses { get; }
+ List Addresses { get; set; }
///
/// Pcap interface flags
///
- uint Flags { get; }
+ uint Flags { get; set; }
///
/// MacAddress of the interface
@@ -59,5 +59,10 @@ public interface IPcapInterface
/// A
///
string ToString();
+
+ ///
+ /// Credentials to use in case of remote pcap
+ ///
+ RemoteAuthentication Credentials { get; }
}
}
\ No newline at end of file
diff --git a/SharpPcap/LibPcap/LibPcapLiveDevice.cs b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
index 7c4a5802..8aaf0dde 100644
--- a/SharpPcap/LibPcap/LibPcapLiveDevice.cs
+++ b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
@@ -37,7 +37,7 @@ public class LibPcapLiveDevice : PcapDevice, ILibPcapLiveDevice
///
/// A 'pcapIf' struct representing
/// the pcap device
- public LibPcapLiveDevice(PcapInterface pcapIf)
+ public LibPcapLiveDevice(IPcapInterface pcapIf)
{
m_pcapIf = pcapIf;
}
diff --git a/SharpPcap/LibPcap/PcapDevice.cs b/SharpPcap/LibPcap/PcapDevice.cs
index 1e69ec7f..dcde3010 100644
--- a/SharpPcap/LibPcap/PcapDevice.cs
+++ b/SharpPcap/LibPcap/PcapDevice.cs
@@ -34,7 +34,7 @@ public abstract partial class PcapDevice : ICaptureDevice
///
/// Low level interface object that contains device specific information
///
- protected PcapInterface m_pcapIf;
+ protected IPcapInterface m_pcapIf;
///
/// Number of packets that this adapter should capture
@@ -66,20 +66,14 @@ public abstract partial class PcapDevice : ICaptureDevice
///
/// Low level pcap device values
///
- public PcapInterface Interface
- {
- get { return m_pcapIf; }
- }
+ public IPcapInterface Interface => m_pcapIf;
private PacketDotNet.LinkLayers linkType;
///
/// Return a value indicating if this adapter is opened
///
- public virtual bool Opened
- {
- get { return !(Handle.IsInvalid || Handle.IsClosed); }
- }
+ public virtual bool Opened => !(Handle.IsInvalid || Handle.IsClosed);
///
/// The file descriptor obtained from pcap_fileno
@@ -110,10 +104,7 @@ internal static string GetLastError(PcapHandle deviceHandle)
///
/// The last pcap error associated with this pcap device
///
- public virtual string LastError
- {
- get { return GetLastError(Handle); }
- }
+ public virtual string LastError => GetLastError(Handle);
///
/// Link type in terms of PacketDotNet.LinkLayers
@@ -179,13 +170,7 @@ public virtual void Close()
///
/// Mac address of the physical device
///
- public virtual System.Net.NetworkInformation.PhysicalAddress MacAddress
- {
- get
- {
- return Interface.MacAddress;
- }
- }
+ public virtual System.Net.NetworkInformation.PhysicalAddress MacAddress => Interface.MacAddress;
///
/// Notify the OnPacketArrival delegates about a newly captured packet
@@ -527,9 +512,9 @@ public override string ToString()
///
public static IEnumerable GetSequence(ICaptureDevice dev, bool maskExceptions = true)
{
+ PacketCapture e;
try
{
- PacketCapture e;
dev.Open();
while (true)
{
diff --git a/SharpPcap/LibPcap/PcapInterface.cs b/SharpPcap/LibPcap/PcapInterface.cs
index 93ce1f36..9a2f7124 100644
--- a/SharpPcap/LibPcap/PcapInterface.cs
+++ b/SharpPcap/LibPcap/PcapInterface.cs
@@ -62,17 +62,17 @@ public class PcapInterface : IPcapInterface
///
/// Addresses associated with this device
///
- public List Addresses { get; internal set; }
+ public List Addresses { get; set; }
///
/// Credentials to use in case of remote pcap
///
- internal RemoteAuthentication Credentials { get; }
+ public RemoteAuthentication Credentials { get; internal set; }
///
/// Pcap interface flags
///
- public uint Flags { get; internal set; }
+ public uint Flags { get; set; }
///
/// MacAddress of the interface
@@ -134,8 +134,10 @@ internal PcapInterface(pcap_if pcapIf, NetworkInterface networkInterface, Remote
PhysicalAddress mac = networkInterface.GetPhysicalAddress();
if (MacAddress == null && mac != null)
{
- PcapAddress pcapAddress = new PcapAddress();
- pcapAddress.Addr = new Sockaddr(mac);
+ PcapAddress pcapAddress = new PcapAddress
+ {
+ Addr = new Sockaddr(mac)
+ };
Addresses.Add(pcapAddress);
if (pcapAddress.Addr.hardwareAddress.GetAddressBytes().Length != 0)
{
diff --git a/SharpPcap/Statistics/StatisticsDevice.cs b/SharpPcap/Statistics/StatisticsDevice.cs
index e278e9a9..4112425f 100644
--- a/SharpPcap/Statistics/StatisticsDevice.cs
+++ b/SharpPcap/Statistics/StatisticsDevice.cs
@@ -40,7 +40,7 @@ public class StatisticsDevice : IPcapDevice
///
/// A 'pcapIf' struct representing
/// the pcap device
- public StatisticsDevice(PcapInterface pcapIf)
+ public StatisticsDevice(IPcapInterface pcapIf)
{
LiveDevice = new LibPcapLiveDevice(pcapIf);
}
diff --git a/Test/MemorySafetyTests.cs b/Test/MemorySafetyTests.cs
index 9617fd9d..eccddc19 100644
--- a/Test/MemorySafetyTests.cs
+++ b/Test/MemorySafetyTests.cs
@@ -21,7 +21,7 @@ namespace Test
public class MemorySafetyTests
{
- private readonly PcapInterface TestInterface = GetPcapDevice().Interface;
+ private readonly IPcapInterface TestInterface = GetPcapDevice().Interface;
[Test]
[Parallelizable(ParallelScope.Children)]
From 6f6348c1c1634bfd9b07ae48140a4cde82797ceb Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Wed, 24 Aug 2022 10:50:09 +0200
Subject: [PATCH 20/53] feat: change version
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 5aa06e25..ab909de0 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.4.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.5.nupkg"
executors:
node:
@@ -77,7 +77,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.4"
+ $env:package_version = "9.0.5"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From aac57e4c51ab738c2ef3630a894dce2cd12ff3ae Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Wed, 24 Aug 2022 11:26:41 +0200
Subject: [PATCH 21/53] feat: resolve interface issues
---
SharpPcap/LibPcap/ILibPcapLiveDevice.cs | 2 +-
SharpPcap/LibPcap/IPcapInterface.cs | 2 +-
SharpPcap/LibPcap/LibPcapLiveDevice.cs | 25 +++++--------------------
SharpPcap/LibPcap/PcapInterface.cs | 4 ++--
4 files changed, 9 insertions(+), 24 deletions(-)
diff --git a/SharpPcap/LibPcap/ILibPcapLiveDevice.cs b/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
index 864c70ee..b9bf787c 100644
--- a/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
+++ b/SharpPcap/LibPcap/ILibPcapLiveDevice.cs
@@ -9,7 +9,7 @@ public interface ILibPcapLiveDevice : ILiveDevice
///
/// Addresses that represent this device
///
- ReadOnlyCollection Addresses { get; }
+ ReadOnlyCollection Addresses { get; }
///
/// Interface flags, see pcap_findalldevs() man page for more info
diff --git a/SharpPcap/LibPcap/IPcapInterface.cs b/SharpPcap/LibPcap/IPcapInterface.cs
index 7c4662c5..1167a63f 100644
--- a/SharpPcap/LibPcap/IPcapInterface.cs
+++ b/SharpPcap/LibPcap/IPcapInterface.cs
@@ -30,7 +30,7 @@ public interface IPcapInterface
///
/// Addresses associated with this device
///
- List Addresses { get; set; }
+ List Addresses { get; set; }
///
/// Pcap interface flags
diff --git a/SharpPcap/LibPcap/LibPcapLiveDevice.cs b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
index 8aaf0dde..69383162 100644
--- a/SharpPcap/LibPcap/LibPcapLiveDevice.cs
+++ b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
@@ -60,42 +60,27 @@ protected LibPcapLiveDevice()
///
/// Gets the pcap name of this network device
///
- public override string Name
- {
- get { return m_pcapIf.Name; }
- }
+ public override string Name => m_pcapIf.Name;
///
/// Addresses that represent this device
///
- public virtual ReadOnlyCollection Addresses
- {
- get { return new ReadOnlyCollection(m_pcapIf.Addresses); }
- }
+ public virtual ReadOnlyCollection Addresses => new ReadOnlyCollection(m_pcapIf.Addresses);
///
/// Gets the pcap description of this device
///
- public override string Description
- {
- get { return m_pcapIf.Description; }
- }
+ public override string Description => m_pcapIf.Description;
///
/// Interface flags, see pcap_findalldevs() man page for more info
///
- public virtual uint Flags
- {
- get { return m_pcapIf.Flags; }
- }
+ public virtual uint Flags => m_pcapIf.Flags;
///
/// True if device is a loopback interface, false if not
///
- public virtual bool Loopback
- {
- get { return (Flags & Pcap.PCAP_IF_LOOPBACK) == 1; }
- }
+ public virtual bool Loopback => (Flags & Pcap.PCAP_IF_LOOPBACK) == 1;
///
/// Open the device. To start capturing call the 'StartCapture' function
diff --git a/SharpPcap/LibPcap/PcapInterface.cs b/SharpPcap/LibPcap/PcapInterface.cs
index 9a2f7124..fdfe548d 100644
--- a/SharpPcap/LibPcap/PcapInterface.cs
+++ b/SharpPcap/LibPcap/PcapInterface.cs
@@ -62,7 +62,7 @@ public class PcapInterface : IPcapInterface
///
/// Addresses associated with this device
///
- public List Addresses { get; set; }
+ public List Addresses { get; set; }
///
/// Credentials to use in case of remote pcap
@@ -84,7 +84,7 @@ internal PcapInterface(pcap_if pcapIf, NetworkInterface networkInterface, Remote
Name = pcapIf.Name;
Description = pcapIf.Description;
Flags = pcapIf.Flags;
- Addresses = new List();
+ Addresses = new List();
GatewayAddresses = new List();
Credentials = credentials;
From 41dc295f8eca9ee1e9bbf4531d5f9c5b588c66ca Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Wed, 24 Aug 2022 11:27:15 +0200
Subject: [PATCH 22/53] feat: change version
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index ab909de0..3f1c5d5a 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.5.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.6.nupkg"
executors:
node:
@@ -77,7 +77,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.5"
+ $env:package_version = "9.0.6"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From c6f2bd52b2d5241c141f3f6d2e5d77b9f4095655 Mon Sep 17 00:00:00 2001
From: Iris van de Zandschulp
Date: Wed, 24 Aug 2022 11:34:41 +0200
Subject: [PATCH 23/53] feat: fix code smell
---
SharpPcap/LibPcap/PcapInterface.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SharpPcap/LibPcap/PcapInterface.cs b/SharpPcap/LibPcap/PcapInterface.cs
index fdfe548d..dc21b927 100644
--- a/SharpPcap/LibPcap/PcapInterface.cs
+++ b/SharpPcap/LibPcap/PcapInterface.cs
@@ -178,7 +178,7 @@ public override string ToString()
}
sb.AppendFormat("Description: {0}\n", Description);
- foreach (PcapAddress addr in Addresses)
+ foreach (IPcapAddress addr in Addresses)
{
sb.AppendFormat("Addresses:\n{0}\n", addr);
}
From 969e83426c78704cf3cb29ab82bacbbc1188627a Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 10:26:44 +0100
Subject: [PATCH 24/53] feat: ITD-1716: fix build when updating sharppcap
---
SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
index 203b4fee..6ab4edcc 100644
--- a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
+++ b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
@@ -175,7 +175,7 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
continue;
}
- int res = LibPcapSafeNativeMethods.pcap_dispatch(Handle, m_pcapPacketCount, Callback, Handle.DangerousGetHandle());
+ int res = LibPcapSafeNativeMethods.pcap_dispatch(handle, m_pcapPacketCount, Callback, handle.DangerousGetHandle());
// pcap_dispatch() returns the number of packets read or, a status value if the value
// is negative
@@ -200,16 +200,16 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
break;
}
break;
- }
- case Pcap.LOOP_EXIT_WITH_ERROR: // An error occurred whilst capturing.
- SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
- return;
- default:
- // This can only be triggered by a bug in libpcap.
- // We can't throw here, sicne that would crash the application
- Trace.TraceError($"SharpPcap: Unknown pcap_loop exit status: {res}");
- SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
- return;
+ case Pcap.LOOP_EXIT_WITH_ERROR: // An error occurred whilst capturing.
+ SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
+ return;
+ default:
+ // This can only be triggered by a bug in libpcap.
+ // We can't throw here, sicne that would crash the application
+ Trace.TraceError($"SharpPcap: Unknown pcap_loop exit status: {res}");
+ SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
+ return;
+ }
}
else // res > 0
{
From 0745778f1c8443235715ed21f03386701c9b73cc Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 10:29:23 +0100
Subject: [PATCH 25/53] feat: ITD-1716: update package version
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 07826f56..33e695c1 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.6.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.7.nupkg"
executors:
node:
@@ -85,7 +85,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.6"
+ $env:package_version = "9.0.7"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From 2b31aed9c9fffd4da1270b5c470938724a4cc54e Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 10:46:33 +0100
Subject: [PATCH 26/53] try fix sonar
---
.circleci/config.yml | 8 --------
1 file changed, 8 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 33e695c1..51492332 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -20,14 +20,6 @@ orbs:
win: circleci/windows@2.2.0
sonar-check: lansweeper/sonar@0.0.6
-commands:
- report:
- steps:
- - store_test_results:
- path: Test/TestResults
- - store_artifacts:
- path: Test/TestResults
-
jobs:
build:
executor: win/default
From fed4ed178a3ac498a0ef999937ea839f0310a58e Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 11:05:12 +0100
Subject: [PATCH 27/53] code smell
---
SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
index 6ab4edcc..f79a04da 100644
--- a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
+++ b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
@@ -199,7 +199,6 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
}
break;
}
- break;
case Pcap.LOOP_EXIT_WITH_ERROR: // An error occurred whilst capturing.
SendCaptureStoppedEvent(CaptureStoppedEventStatus.ErrorWhileCapturing);
return;
From c67a5d55c2718bc6bedd03e1fb49b5978f67324e Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 11:18:26 +0100
Subject: [PATCH 28/53] code smells
---
SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
index f79a04da..445b3f40 100644
--- a/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
+++ b/SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
@@ -175,7 +175,9 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
continue;
}
+ #pragma warning disable S3869 // "SafeHandle.DangerousGetHandle" should not be called
int res = LibPcapSafeNativeMethods.pcap_dispatch(handle, m_pcapPacketCount, Callback, handle.DangerousGetHandle());
+ #pragma warning restore S3869 // "SafeHandle.DangerousGetHandle" should not be called
// pcap_dispatch() returns the number of packets read or, a status value if the value
// is negative
@@ -192,7 +194,9 @@ protected virtual void CaptureThread(CancellationToken cancellationToken)
// from causing premature exiting from the capture loop we only consider
// exhausted events to cause an escape from the loop when they are from
// offline devices, ie. files read from disk
+ #pragma warning disable S3060
if (this is CaptureReaderDevice)
+ #pragma warning restore S3060
{
SendCaptureStoppedEvent(CaptureStoppedEventStatus.CompletedWithoutError);
return;
From 3eb1ceff76a7e918298ce4eec42ad3a7e473ad77 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 11:32:50 +0100
Subject: [PATCH 29/53] try fix build
---
.circleci/config.yml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 51492332..33e695c1 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -20,6 +20,14 @@ orbs:
win: circleci/windows@2.2.0
sonar-check: lansweeper/sonar@0.0.6
+commands:
+ report:
+ steps:
+ - store_test_results:
+ path: Test/TestResults
+ - store_artifacts:
+ path: Test/TestResults
+
jobs:
build:
executor: win/default
From 307d033bf09451a9c2c0d24eefd87ba3ff7ab17d Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Fri, 24 Nov 2023 15:08:31 +0100
Subject: [PATCH 30/53] fix: ITD-1716: try to fix package publish
---
SharpPcap/SharpPcap.csproj | 1 -
1 file changed, 1 deletion(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index faf780aa..23cdadf7 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -6,7 +6,6 @@
Lansweeper
Lansweeper SharpPcap
Lansweeper SharpPcap
- 6.2.5
A packet capture framework for .NET
Tamir Gal, Chris Morgan and others
https://github.com/chmorgan/sharppcap
From 69f83c97c226342633222905878986c8d14e024e Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Mon, 27 Nov 2023 18:02:32 +0100
Subject: [PATCH 31/53] feat: ITD-1716: MacOS trimming support
---
SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs | 4 ++++
SharpPcap/LibPcap/NativeLibraryHelper.cs | 2 +-
SharpPcap/SharpPcap.csproj | 5 +++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
index 7e8308b7..7add439d 100644
--- a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
+++ b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
@@ -41,7 +41,11 @@ internal static partial class LibPcapSafeNativeMethods
// This file is called $assembly_name.dll.config and is placed in the
// same directory as the assembly
// See http://www.mono-project.com/Interop_with_Native_Libraries#Library_Names
+#if OSX
+ private const string PCAP_DLL = "libpcap";
+#else
private const string PCAP_DLL = "wpcap";
+#endif
[DllImport(PCAP_DLL, CallingConvention = CallingConvention.Cdecl)]
internal extern static int pcap_init(
diff --git a/SharpPcap/LibPcap/NativeLibraryHelper.cs b/SharpPcap/LibPcap/NativeLibraryHelper.cs
index 0b36e099..1d97dc74 100644
--- a/SharpPcap/LibPcap/NativeLibraryHelper.cs
+++ b/SharpPcap/LibPcap/NativeLibraryHelper.cs
@@ -35,7 +35,7 @@ public static void SetDllImportResolver(Assembly assembly, DllImportResolver res
null
);
- setDllImportResolverMethod.Invoke(null, new object[] {
+ setDllImportResolverMethod?.Invoke(null, new object[] {
assembly,
Delegate.CreateDelegate(dllImportResolverType, resolver, "Invoke")
});
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 23cdadf7..aaa9e959 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -34,4 +34,9 @@
<_Parameter1>Test
+
+
+ OSX
+
+
From c6f61c5044040b414118f2c8234dae5593b80393 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Mon, 27 Nov 2023 18:04:29 +0100
Subject: [PATCH 32/53] indentation
---
SharpPcap/SharpPcap.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index aaa9e959..4d0d9515 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -36,7 +36,7 @@
- OSX
+ OSX
From bd23758ba44c154d915f45661f4a49f6f2c2a662 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Mon, 27 Nov 2023 18:05:54 +0100
Subject: [PATCH 33/53] feat: ITD-1716: change version
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 33e695c1..4e09de5f 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.7.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.8.nupkg"
executors:
node:
@@ -85,7 +85,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.7"
+ $env:package_version = "9.0.8"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From c8249ab91bcee7baa8495be4d98e6ebbef7937c3 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Tue, 28 Nov 2023 13:28:26 +0100
Subject: [PATCH 34/53] feat: ITD-1716: use RuntimeIdentifier instead of
RuntimeInformation
---
SharpPcap/SharpPcap.csproj | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 4d0d9515..42f481ee 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -1,6 +1,7 @@
netstandard2.0
+ win-x64;osx-x64;linux-x64
9.0.1
Lansweeper.SharpPcap
Lansweeper
@@ -35,8 +36,8 @@
-
- OSX
+
+ OSX
From 92e9a9209396bfc25c926f9e5f3d9470cf2b687b Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Tue, 28 Nov 2023 13:32:36 +0100
Subject: [PATCH 35/53] feat: ITD-1716: extend DefineConstants
---
SharpPcap/SharpPcap.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 42f481ee..e5d9b5a1 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -37,7 +37,7 @@
- OSX
+ $(DefineConstants);OSX
From 843cdc2c54ae92bf8e0b9592e0d18ce628c8afbc Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Tue, 28 Nov 2023 14:07:26 +0100
Subject: [PATCH 36/53] feat: ITD-1716: fix build
---
SharpPcap/SharpPcap.csproj | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index e5d9b5a1..43b0f947 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -23,6 +23,7 @@
7.3
true
true
+ $(DefineConstants);OSX
@@ -35,9 +36,4 @@
<_Parameter1>Test
-
-
- $(DefineConstants);OSX
-
-
From ea5fff5f532171e879305ef14d128542ef063bf3 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Wed, 29 Nov 2023 08:51:59 +0100
Subject: [PATCH 37/53] feat: ITD-1716: cleanup (not working)
---
SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs | 4 ----
SharpPcap/SharpPcap.csproj | 2 --
2 files changed, 6 deletions(-)
diff --git a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
index 7add439d..7e8308b7 100644
--- a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
+++ b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
@@ -41,11 +41,7 @@ internal static partial class LibPcapSafeNativeMethods
// This file is called $assembly_name.dll.config and is placed in the
// same directory as the assembly
// See http://www.mono-project.com/Interop_with_Native_Libraries#Library_Names
-#if OSX
- private const string PCAP_DLL = "libpcap";
-#else
private const string PCAP_DLL = "wpcap";
-#endif
[DllImport(PCAP_DLL, CallingConvention = CallingConvention.Cdecl)]
internal extern static int pcap_init(
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 43b0f947..23cdadf7 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -1,7 +1,6 @@
netstandard2.0
- win-x64;osx-x64;linux-x64
9.0.1
Lansweeper.SharpPcap
Lansweeper
@@ -23,7 +22,6 @@
7.3
true
true
- $(DefineConstants);OSX
From e8bbef8c41c444ad33514a99aa811e89f8884987 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Wed, 29 Nov 2023 08:53:28 +0100
Subject: [PATCH 38/53] update package
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 4e09de5f..ef463df7 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.8.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.9.nupkg"
executors:
node:
@@ -85,7 +85,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.8"
+ $env:package_version = "9.0.9"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From 3444ec2526fdcb44564f57473be640d3fbd094c1 Mon Sep 17 00:00:00 2001
From: Joran Van Craenenbroeck
Date: Wed, 29 Nov 2023 09:16:58 +0100
Subject: [PATCH 39/53] undo null check
---
SharpPcap/LibPcap/NativeLibraryHelper.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SharpPcap/LibPcap/NativeLibraryHelper.cs b/SharpPcap/LibPcap/NativeLibraryHelper.cs
index 1d97dc74..0b36e099 100644
--- a/SharpPcap/LibPcap/NativeLibraryHelper.cs
+++ b/SharpPcap/LibPcap/NativeLibraryHelper.cs
@@ -35,7 +35,7 @@ public static void SetDllImportResolver(Assembly assembly, DllImportResolver res
null
);
- setDllImportResolverMethod?.Invoke(null, new object[] {
+ setDllImportResolverMethod.Invoke(null, new object[] {
assembly,
Delegate.CreateDelegate(dllImportResolverType, resolver, "Invoke")
});
From 0ea973c635ec05cdefc41e0eb6cb7943a656754a Mon Sep 17 00:00:00 2001
From: Lansweeper Bot
<78368012+LansweeperCloudDevelopment@users.noreply.github.com>
Date: Wed, 20 Nov 2024 14:34:19 +0100
Subject: [PATCH 40/53] Add catalog file ./catalog-info.repo.yml [skip ci]
---
catalog-info.repo.yml | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 catalog-info.repo.yml
diff --git a/catalog-info.repo.yml b/catalog-info.repo.yml
new file mode 100644
index 00000000..e3b96ec3
--- /dev/null
+++ b/catalog-info.repo.yml
@@ -0,0 +1,11 @@
+apiVersion: backstage.io/v1alpha1
+kind: Component
+metadata:
+ name: sharppcap
+ description: Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
+ annotations:
+ github.com/project-slug: Lansweeper/sharppcap
+spec:
+ type: github-repository
+ owner: unknown
+ lifecycle: stable
\ No newline at end of file
From 2b4abd3f3fa721474a0557c63b53c3e0c33317a3 Mon Sep 17 00:00:00 2001
From: Lansweeper Bot
<78368012+LansweeperCloudDevelopment@users.noreply.github.com>
Date: Wed, 20 Nov 2024 15:37:47 +0100
Subject: [PATCH 41/53] Add catalog file ./catalog-info.repo.yaml [skip ci]
---
catalog-info.repo.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 catalog-info.repo.yaml
diff --git a/catalog-info.repo.yaml b/catalog-info.repo.yaml
new file mode 100644
index 00000000..e3b96ec3
--- /dev/null
+++ b/catalog-info.repo.yaml
@@ -0,0 +1,11 @@
+apiVersion: backstage.io/v1alpha1
+kind: Component
+metadata:
+ name: sharppcap
+ description: Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
+ annotations:
+ github.com/project-slug: Lansweeper/sharppcap
+spec:
+ type: github-repository
+ owner: unknown
+ lifecycle: stable
\ No newline at end of file
From 718157ecaa4c3cda41442e9f15d2836f38fcb432 Mon Sep 17 00:00:00 2001
From: Lansweeper Bot
<78368012+LansweeperCloudDevelopment@users.noreply.github.com>
Date: Wed, 20 Nov 2024 16:44:57 +0100
Subject: [PATCH 42/53] Remove file ./catalog-info.repo.yml [skip ci]
---
catalog-info.repo.yml | 11 -----------
1 file changed, 11 deletions(-)
delete mode 100644 catalog-info.repo.yml
diff --git a/catalog-info.repo.yml b/catalog-info.repo.yml
deleted file mode 100644
index e3b96ec3..00000000
--- a/catalog-info.repo.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-apiVersion: backstage.io/v1alpha1
-kind: Component
-metadata:
- name: sharppcap
- description: Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
- annotations:
- github.com/project-slug: Lansweeper/sharppcap
-spec:
- type: github-repository
- owner: unknown
- lifecycle: stable
\ No newline at end of file
From 13a09fe7430f7dc4fcdc341c5ae0fedfd489d37f Mon Sep 17 00:00:00 2001
From: Lansweeper Bot
<78368012+LansweeperCloudDevelopment@users.noreply.github.com>
Date: Tue, 26 Nov 2024 13:38:10 +0100
Subject: [PATCH 43/53] Update ./catalog-info.repo.yaml [skip ci]
---
catalog-info.repo.yaml | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/catalog-info.repo.yaml b/catalog-info.repo.yaml
index e3b96ec3..6742354c 100644
--- a/catalog-info.repo.yaml
+++ b/catalog-info.repo.yaml
@@ -1,11 +1,11 @@
-apiVersion: backstage.io/v1alpha1
-kind: Component
+apiVersion: lansweeper.com/v1alpha1
+kind: Repository
metadata:
- name: sharppcap
- description: Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
annotations:
github.com/project-slug: Lansweeper/sharppcap
+ description: Official repository - Fully managed, cross platform (Windows, Mac,
+ Linux) .NET library for capturing packets
+ name: sharppcap
spec:
- type: github-repository
- owner: unknown
- lifecycle: stable
\ No newline at end of file
+ lifecycle: stable
+ owner: unknown
\ No newline at end of file
From 3dcac3c63cfc299749c12140d49811e7e73e1856 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Tue, 14 Jan 2025 12:28:14 +0100
Subject: [PATCH 44/53] fix circle ci for .net 8
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index ef463df7..ae492a00 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -17,7 +17,7 @@ executors:
- image: circleci/node:12
orbs:
- win: circleci/windows@2.2.0
+ win: circleci/windows@5.0.0
sonar-check: lansweeper/sonar@0.0.6
commands:
From bb6ef49d4d19b4d263d38525fe1b6d80893b55d8 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Tue, 14 Jan 2025 16:14:50 +0100
Subject: [PATCH 45/53] removed license check and code coverage
---
.github/workflows/dotnet-core.yml | 26 +++++++++++++-------------
scripts/test.sh | 6 +++---
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml
index 86dd38ac..23f8e99f 100644
--- a/.github/workflows/dotnet-core.yml
+++ b/.github/workflows/dotnet-core.yml
@@ -26,8 +26,8 @@ jobs:
run: dotnet build SharpPcap/SharpPcap.csproj
- name: Test
run: sudo -E bash scripts/test.sh
- env:
- CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
+ # env:
+ # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- run: sudo chmod -R +r Test/TestResults
if: always()
@@ -55,14 +55,14 @@ jobs:
# Flag to toggle pushing symbols along with nuget package to the server, disabled by default
INCLUDE_SYMBOLS: true
- license-check:
- # We use https://github.com/fsfe/reuse-tool to ensure EVERY file has correct license and copyright info
- # Either in the file itself, or in .reuse\dep5 for binary files and files that don't support comments
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v4
- - uses: actions/setup-python@v5
- with:
- python-version: '3.10'
- - run: pip install -r requirements.txt
- - run: reuse lint
+ # license-check:
+ # # We use https://github.com/fsfe/reuse-tool to ensure EVERY file has correct license and copyright info
+ # # Either in the file itself, or in .reuse\dep5 for binary files and files that don't support comments
+ # runs-on: ubuntu-latest
+ # steps:
+ # - uses: actions/checkout@v4
+ # - uses: actions/setup-python@v5
+ # with:
+ # python-version: '3.10'
+ # - run: pip install -r requirements.txt
+ # - run: reuse lint
diff --git a/scripts/test.sh b/scripts/test.sh
index 7c5d769b..9da749ce 100644
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -24,6 +24,6 @@ fi
dotnet test "${TEST_ARGS[@]}"
-# coverage
-pip install codecov-cli || python3 -m pip install codecov-cli
-codecovcli upload-process
+# # coverage
+# pip install codecov-cli || python3 -m pip install codecov-cli
+# codecovcli upload-process
From 22530539da14fd70c84376d03b1f53194be41da3 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Tue, 14 Jan 2025 16:22:44 +0100
Subject: [PATCH 46/53] specifying NuGetPackage version
---
.circleci/config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index ae492a00..f5bf01c9 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -85,7 +85,7 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "9.0.9"
+ $env:package_version = "10.0.0-alpha"
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
From 3ae66f3b7e2698b7fefb195fa879e370b2335714 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Tue, 14 Jan 2025 16:48:32 +0100
Subject: [PATCH 47/53] chore: fix nuget publish
---
.circleci/config.yml | 2 +-
.github/workflows/dotnet-core.yml | 20 ++++++++++----------
SharpPcap/SharpPcap.csproj | 2 +-
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index f5bf01c9..a184a388 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -86,7 +86,7 @@ jobs:
name: Set correct version in csproj file, build and pack it
command: |
$env:package_version = "10.0.0-alpha"
-
+
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
$cn.Project.PropertyGroup.Version="$env:package_version"
diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml
index 23f8e99f..79282220 100644
--- a/.github/workflows/dotnet-core.yml
+++ b/.github/workflows/dotnet-core.yml
@@ -42,18 +42,18 @@ jobs:
name: artifacts
path: Test/TestResults/
- - name: publish on version change
- id: publish_nuget
- uses: alirezanet/publish-nuget@v3.1.0
- with:
- # Filepath of the project to be packaged, relative to root of repository
- PROJECT_FILE_PATH: SharpPcap/SharpPcap.csproj
+ # - name: publish on version change
+ # id: publish_nuget
+ # uses: alirezanet/publish-nuget@v3.1.0
+ # with:
+ # # Filepath of the project to be packaged, relative to root of repository
+ # PROJECT_FILE_PATH: SharpPcap/SharpPcap.csproj
- # API key to authenticate with NuGet server
- NUGET_KEY: ${{secrets.NUGET_API_KEY}}
+ # # API key to authenticate with NuGet server
+ # NUGET_KEY: ${{secrets.NUGET_API_KEY}}
- # Flag to toggle pushing symbols along with nuget package to the server, disabled by default
- INCLUDE_SYMBOLS: true
+ # # Flag to toggle pushing symbols along with nuget package to the server, disabled by default
+ # INCLUDE_SYMBOLS: true
# license-check:
# # We use https://github.com/fsfe/reuse-tool to ensure EVERY file has correct license and copyright info
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 9743de87..3a6e59ac 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -8,7 +8,7 @@ SPDX-License-Identifier: MIT
netstandard2.0;net8.0
- 9.0.1
+ 10.0.0-alpha
Lansweeper.SharpPcap
Lansweeper
Lansweeper SharpPcap
From 41da05c66dd4c7702af2c325bc04babf39c849fc Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Tue, 14 Jan 2025 17:42:32 +0100
Subject: [PATCH 48/53] corrected version
---
.circleci/config.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index a184a388..bd18eb91 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.9.0.9.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.10.0.0-alpha.nupkg"
executors:
node:
@@ -86,7 +86,7 @@ jobs:
name: Set correct version in csproj file, build and pack it
command: |
$env:package_version = "10.0.0-alpha"
-
+
$file = Get-Item << pipeline.parameters.csproj-file >>
[xml]$cn = Get-Content $file
$cn.Project.PropertyGroup.Version="$env:package_version"
From 086af1b85efdc213d7e10e2e9b4732321da2c847 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Wed, 15 Jan 2025 10:32:12 +0100
Subject: [PATCH 49/53] support .NET8 only
---
.../Example03.BasicCap.csproj | 1 +
.../PublishProfiles/lin-arm64-aot.pubxml | 18 +++++
.../PublishProfiles/lin-x64-aot.pubxml | 19 +++++
.../Properties/PublishProfiles/lin-x64.pubxml | 18 +++++
.../PublishProfiles/win-x64-aot.pubxml | 19 +++++
.../Properties/PublishProfiles/win-x64.pubxml | 18 +++++
.../WinformsExample/WinformsExample.csproj | 7 +-
SharpPcap/SharpPcap.csproj | 76 +++++++++----------
Test/Test.csproj | 1 -
9 files changed, 132 insertions(+), 45 deletions(-)
create mode 100644 Examples/Example3.BasicCap/Properties/PublishProfiles/lin-arm64-aot.pubxml
create mode 100644 Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64-aot.pubxml
create mode 100644 Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64.pubxml
create mode 100644 Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64-aot.pubxml
create mode 100644 Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64.pubxml
diff --git a/Examples/Example3.BasicCap/Example03.BasicCap.csproj b/Examples/Example3.BasicCap/Example03.BasicCap.csproj
index b8bec4e6..58129abf 100644
--- a/Examples/Example3.BasicCap/Example03.BasicCap.csproj
+++ b/Examples/Example3.BasicCap/Example03.BasicCap.csproj
@@ -2,6 +2,7 @@
Exe
net8.0
+ true
diff --git a/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-arm64-aot.pubxml b/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-arm64-aot.pubxml
new file mode 100644
index 00000000..9c1f3e72
--- /dev/null
+++ b/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-arm64-aot.pubxml
@@ -0,0 +1,18 @@
+
+
+
+
+ Release
+ Any CPU
+ .\publish\lin-arm64-aot\
+ FileSystem
+ <_TargetId>Folder
+ net8.0
+ linux-arm64
+ true
+ false
+ true
+
+
\ No newline at end of file
diff --git a/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64-aot.pubxml b/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64-aot.pubxml
new file mode 100644
index 00000000..fa31ee67
--- /dev/null
+++ b/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64-aot.pubxml
@@ -0,0 +1,19 @@
+
+
+
+
+ Release
+ Any CPU
+ .\publish\lin-x64-aot\
+ FileSystem
+ <_TargetId>Folder
+ net8.0
+ linux-x64
+ true
+ false
+ false
+ true
+
+
\ No newline at end of file
diff --git a/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64.pubxml b/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64.pubxml
new file mode 100644
index 00000000..92f1dc8e
--- /dev/null
+++ b/Examples/Example3.BasicCap/Properties/PublishProfiles/lin-x64.pubxml
@@ -0,0 +1,18 @@
+
+
+
+
+ Release
+ Any CPU
+ .\publish\lin-x64\
+ FileSystem
+ <_TargetId>Folder
+ net8.0
+ linux-x64
+ true
+ true
+ false
+
+
\ No newline at end of file
diff --git a/Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64-aot.pubxml b/Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64-aot.pubxml
new file mode 100644
index 00000000..f77495b0
--- /dev/null
+++ b/Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64-aot.pubxml
@@ -0,0 +1,19 @@
+
+
+
+
+ Release
+ Any CPU
+ .\publish\win-x64-aot\
+ FileSystem
+ <_TargetId>Folder
+ net8.0
+ win-x64
+ true
+ false
+ false
+ true
+
+
\ No newline at end of file
diff --git a/Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64.pubxml b/Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64.pubxml
new file mode 100644
index 00000000..a829582b
--- /dev/null
+++ b/Examples/Example3.BasicCap/Properties/PublishProfiles/win-x64.pubxml
@@ -0,0 +1,18 @@
+
+
+
+
+ Release
+ Any CPU
+ .\publish\win-x64\
+ FileSystem
+ <_TargetId>Folder
+ net8.0
+ win-x64
+ true
+ true
+ false
+
+
\ No newline at end of file
diff --git a/Examples/WinformsExample/WinformsExample.csproj b/Examples/WinformsExample/WinformsExample.csproj
index 175daa6b..55833830 100644
--- a/Examples/WinformsExample/WinformsExample.csproj
+++ b/Examples/WinformsExample/WinformsExample.csproj
@@ -1,13 +1,10 @@
WinExe
- net48
+ net8.0-windows
+ true
true
-
-
-
-
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index 3a6e59ac..f627c290 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -6,43 +6,41 @@ Copyright 2008-2011 Chris Morgan
SPDX-License-Identifier: MIT
-->
-
- netstandard2.0;net8.0
- 10.0.0-alpha
- Lansweeper.SharpPcap
- Lansweeper
- Lansweeper SharpPcap
- Lansweeper SharpPcap
- A packet capture framework for .NET
- Tamir Gal, Chris Morgan and others
- https://github.com/Lansweeper/sharppcap
- false
- https://github.com/Lansweeper/sharppcap
- true
- true
- true
- snupkg
- Tamir Gal, Chris Morgan and others
-
- SharpPcap is a cross-platform(Windows, Mac, Linux) packet capture framework for the .NET environment.
- It provides an API for capturing, injecting, analyzing and building packets using any .NET language such as C# and VB.NET.
-
- MIT
- true
- true
-
-
- true
-
-
-
-
-
-
-
-
-
- <_Parameter1>Test
-
-
+
+ net8.0
+ 10.0.0-alpha
+ Lansweeper.SharpPcap
+ Lansweeper
+ Lansweeper SharpPcap
+ Lansweeper SharpPcap
+ A packet capture framework for .NET
+ Tamir Gal, Chris Morgan and others
+ https://github.com/Lansweeper/sharppcap
+ false
+ https://github.com/Lansweeper/sharppcap
+ true
+ true
+ true
+ snupkg
+ Tamir Gal, Chris Morgan and others
+
+ SharpPcap is a cross-platform(Windows, Mac, Linux) packet capture framework for the .NET environment.
+ It provides an API for capturing, injecting, analyzing and building packets using any .NET language such as C# and VB.NET.
+
+ MIT
+ true
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+ <_Parameter1>Test
+
+
diff --git a/Test/Test.csproj b/Test/Test.csproj
index ceb77db9..d3819471 100644
--- a/Test/Test.csproj
+++ b/Test/Test.csproj
@@ -9,7 +9,6 @@ SPDX-License-Identifier: MIT
true
net8.0
- $(TargetFrameworks);net48
opencover
From 6b769dc0577917ebe0113de59b998f60c91bc435 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Wed, 15 Jan 2025 11:58:24 +0100
Subject: [PATCH 50/53] using pcap_open_live instead of pcap_open
---
SharpPcap/LibPcap/LibPcapLiveDevice.cs | 2 +-
SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/SharpPcap/LibPcap/LibPcapLiveDevice.cs b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
index 91f6ac86..949f0b9e 100644
--- a/SharpPcap/LibPcap/LibPcapLiveDevice.cs
+++ b/SharpPcap/LibPcap/LibPcapLiveDevice.cs
@@ -150,7 +150,7 @@ public override void Open(DeviceConfiguration configuration)
immediateMode = null;
try
{
- Handle = LibPcapSafeNativeMethods.pcap_open(
+ Handle = LibPcapSafeNativeMethods.pcap_open_live(
Name, // name of the device
configuration.Snaplen, // portion of the packet to capture.
(short)mode, // flags
diff --git a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
index 3c6fe3ff..1b931e1e 100644
--- a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
+++ b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
@@ -48,7 +48,7 @@ out ErrorBuffer /* char* */ errbuf
internal extern static void pcap_freealldevs(IntPtr /* pcap_if_t * */ alldevs);
[DllImport(PCAP_DLL, CallingConvention = CallingConvention.Cdecl)]
- internal extern static PcapHandle /* pcap_t* */ pcap_open(
+ internal extern static PcapHandle /* pcap_t* */ pcap_open_live(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PcapStringMarshaler))] string dev,
int packetLen,
int flags,
From 6c8f6b92246e602d244ef1a208f304ea03b439be Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Wed, 15 Jan 2025 14:18:20 +0100
Subject: [PATCH 51/53] mitigated some AoT risks
---
Directory.Build.props | 1 -
SharpPcap/LibPcap/BpfProgram.cs | 2 +-
SharpPcap/LibPcap/PcapStatistics.cs | 20 +++++++++-----------
3 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 36935657..28e561f8 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -7,6 +7,5 @@ SPDX-License-Identifier: MIT
true
full
true
- 8.0
diff --git a/SharpPcap/LibPcap/BpfProgram.cs b/SharpPcap/LibPcap/BpfProgram.cs
index a017db47..c45411c2 100644
--- a/SharpPcap/LibPcap/BpfProgram.cs
+++ b/SharpPcap/LibPcap/BpfProgram.cs
@@ -87,7 +87,7 @@ public static BpfProgram Create(LinkLayers linktype, string filter, int optimize
private BpfProgram()
: base(true)
{
- var bpfProgram = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.bpf_program)));
+ var bpfProgram = Marshal.AllocHGlobal(Marshal.SizeOf());
SetHandle(bpfProgram);
}
diff --git a/SharpPcap/LibPcap/PcapStatistics.cs b/SharpPcap/LibPcap/PcapStatistics.cs
index 5ea469f4..e6ef962c 100644
--- a/SharpPcap/LibPcap/PcapStatistics.cs
+++ b/SharpPcap/LibPcap/PcapStatistics.cs
@@ -43,12 +43,12 @@ internal PcapStatistics(PcapHandle pcap_t)
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
// allocate memory for the struct
- stat = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_stat_unix)));
+ stat = Marshal.AllocHGlobal(Marshal.SizeOf());
}
else
{
// allocate memory for the struct
- stat = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_stat_windows)));
+ stat = Marshal.AllocHGlobal(Marshal.SizeOf());
}
// retrieve the stats
@@ -73,28 +73,26 @@ internal PcapStatistics(PcapHandle pcap_t)
// marshal the unmanaged memory into an object of the proper type
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
- var managedStat = (PcapUnmanagedStructures.pcap_stat_unix)Marshal.PtrToStructure(stat,
- typeof(PcapUnmanagedStructures.pcap_stat_unix));
+ var managedStat = Marshal.PtrToStructure< PcapUnmanagedStructures.pcap_stat_unix>(stat);
// copy the values
- this.ReceivedPackets = (uint)managedStat.ps_recv.ToInt64();
- this.DroppedPackets = (uint)managedStat.ps_drop.ToInt64();
+ ReceivedPackets = (uint)managedStat.ps_recv.ToInt64();
+ DroppedPackets = (uint)managedStat.ps_drop.ToInt64();
// this.InterfaceDroppedPackets = (uint)managedStat.ps_ifdrop;
}
else
{
- var managedStat = (PcapUnmanagedStructures.pcap_stat_windows)Marshal.PtrToStructure(stat,
- typeof(PcapUnmanagedStructures.pcap_stat_windows));
+ var managedStat = Marshal.PtrToStructure(stat);
// copy the values
- this.ReceivedPackets = (uint)managedStat.ps_recv;
- this.DroppedPackets = (uint)managedStat.ps_drop;
+ ReceivedPackets = managedStat.ps_recv;
+ DroppedPackets = managedStat.ps_drop;
// this.InterfaceDroppedPackets = (uint)managedStat.ps_ifdrop;
}
// NOTE: Not supported on unix or npcap, no need to
// put a bogus value in this field
- this.InterfaceDroppedPackets = 0;
+ InterfaceDroppedPackets = 0;
// free the stats
Marshal.FreeHGlobal(stat);
From b99ba96db110f5800522b7e1b441e65d6c23b53d Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Wed, 15 Jan 2025 15:45:18 +0100
Subject: [PATCH 52/53] =?UTF-8?q?Added=20separate=20NuGet=20package=20for?=
=?UTF-8?q?=20StaticLinking=20=F0=9F=94=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.circleci/config.yml | 47 +++++++----
SharpPcap.sln | 5 +-
.../LibPcapSafeNativeMethods.Interop.cs | 4 +
SharpPcap/README.md | 75 ++++++++++++++++++
SharpPcap/README_StaticLinking.md | 79 +++++++++++++++++++
SharpPcap/SharpPcap.csproj | 11 ++-
6 files changed, 202 insertions(+), 19 deletions(-)
create mode 100644 SharpPcap/README.md
create mode 100644 SharpPcap/README_StaticLinking.md
diff --git a/.circleci/config.yml b/.circleci/config.yml
index bd18eb91..7bd4fa53 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,10 @@ parameters:
default: "Lansweeper_sharppcap"
nuget-output-file:
type: string
- default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.10.0.0-alpha.nupkg"
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.$PACKAGE_VERSION.nupkg"
+ nuget-output-file-static:
+ type: string
+ default: "SharpPcap/bin/Release/Lansweeper.SharpPcap.StaticLinking.$PACKAGE_VERSION.nupkg"
executors:
node:
@@ -31,20 +34,25 @@ commands:
jobs:
build:
executor: win/default
-
steps:
- checkout
+ - run:
+ name: Extract version from .csproj
+ command: |
+ $file = Get-Item << parameters.csproj-file >>
+ [xml]$cn = Get-Content $file
+ $version = $cn.Project.PropertyGroup.Version
+ echo "##vso[task.setvariable variable=PACKAGE_VERSION]$version"
- run:
name: Install SonarScanner for MSBuild .NET Core Global Tool
command: dotnet tool install --global dotnet-sonarscanner
- run:
name: Start SonarScanner
- command: dotnet sonarscanner begin /k:"<< pipeline.parameters.sonar-project >>" /d:sonar.verbose=true /o:"lansweeper" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=$Env:SONAR_TOKEN /d:sonar.language="cs"
- - run: dotnet build << pipeline.parameters.csproj-file >> --configuration Release
+ command: dotnet sonarscanner begin /k="<< parameters.sonar-project >>" /d:sonar.verbose=true /o:"lansweeper" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=$Env:SONAR_TOKEN /d:sonar.language="cs"
+ - run: dotnet build << parameters.csproj-file >> --configuration Release
- run:
name: Upload SonarScanner results
command: dotnet sonarscanner end /d:sonar.login=$Env:SONAR_TOKEN
-
- persist_to_workspace:
root: .
paths:
@@ -54,6 +62,8 @@ jobs:
executor:
name: win/default
steps:
+ - attach_workspace:
+ at: .
- run:
name: Create local nuget config file
command: |
@@ -85,20 +95,25 @@ jobs:
- run:
name: Set correct version in csproj file, build and pack it
command: |
- $env:package_version = "10.0.0-alpha"
-
- $file = Get-Item << pipeline.parameters.csproj-file >>
+ $file = Get-Item << parameters.csproj-file >>
[xml]$cn = Get-Content $file
- $cn.Project.PropertyGroup.Version="$env:package_version"
+ $cn.Project.PropertyGroup.Version="$env:PACKAGE_VERSION"
$cn.Save($file.FullName)
- type ./<< pipeline.parameters.csproj-file >>
+ type ./<< parameters.csproj-file >>
- run:
- name: Pack the package
- command: dotnet pack << pipeline.parameters.csproj-file >> --configuration Release
+ name: Pack the default package
+ command: dotnet pack << parameters.csproj-file >> --configuration Release
- run:
- name: Publish the package
+ name: Pack the StaticLinking package
+ command: dotnet pack << parameters.csproj-file >> --configuration StaticLinking --configuration Release
+ - run:
+ name: Publish the default package
command: |
- dotnet nuget push << pipeline.parameters.nuget-output-file >> --source "github" --api-key $env:GITHUB_TOKEN
+ dotnet nuget push << parameters.nuget-output-file >> --source "github" --api-key $env:GITHUB_TOKEN
+ - run:
+ name: Publish the StaticLinking package
+ command: |
+ dotnet nuget push << parameters.nuget-output-file-static >> --source "github" --api-key $env:GITHUB_TOKEN
sonar:
executor: node
@@ -107,7 +122,7 @@ jobs:
at: .
- sonar-check/get_sonar_status:
report_file: "/home/circleci/project/.sonarqube/out/.sonar/report-task.txt"
-
+
workflows:
version: 2
@@ -155,7 +170,7 @@ workflows:
filters:
branches:
only: master
-
+
run-daily-tests:
triggers:
- schedule:
diff --git a/SharpPcap.sln b/SharpPcap.sln
index d2009df9..5f242eb4 100644
--- a/SharpPcap.sln
+++ b/SharpPcap.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29025.244
+# Visual Studio Version 17
+VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example03.BasicCap", "Examples\Example3.BasicCap\Example03.BasicCap.csproj", "{2B5462B9-068B-46E8-B139-E3B9211A48B1}"
EndProject
@@ -45,6 +45,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
+ .circleci\config.yml = .circleci\config.yml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
diff --git a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
index 1b931e1e..11af9311 100644
--- a/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
+++ b/SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
@@ -17,12 +17,16 @@ namespace SharpPcap.LibPcap
[SuppressUnmanagedCodeSecurity]
internal static partial class LibPcapSafeNativeMethods
{
+#if STATIC_LINKING
+ private const string PCAP_DLL = "libpcap";
+#else
// NOTE: For mono users on non-windows platforms a .config file is used to map
// the windows dll name to the unix/mac library name
// This file is called $assembly_name.dll.config and is placed in the
// same directory as the assembly
// See http://www.mono-project.com/Interop_with_Native_Libraries#Library_Names
private const string PCAP_DLL = "wpcap";
+#endif
[DllImport(PCAP_DLL, CallingConvention = CallingConvention.Cdecl)]
internal extern static int pcap_init(
diff --git a/SharpPcap/README.md b/SharpPcap/README.md
new file mode 100644
index 00000000..38a0d5c4
--- /dev/null
+++ b/SharpPcap/README.md
@@ -0,0 +1,75 @@
+# Lansweeper SharpPcap
+
+This is a fork of the original SharpPcap project, which is a cross-platform packet capture framework for the .NET environment.
+The original project can be found [here](https://github.com/dotpcap/sharppcap)
+
+This fork is maintained by Lansweeper and can be found [here](https://github.com/Lansweeper/sharppcap)
+
+> This is the default version. For the version with static linking, see `Lansweeper.SharpPcap.StaticLinking`.
+
+## Changes to the original project
+- Allow for AoT compilation
+- Added support for ARM64
+- Better abstractions and better testability
+- Removed netstandard2.0 support
+
+SharpPcap is a cross-platform (Windows, Mac, Linux) packet capture framework for the .NET environment.
+It provides an API for capturing, injecting, analyzing, and building packets using any .NET language such as C# and VB.NET.
+
+## Features
+
+- Cross-platform support (Windows, Mac, Linux)
+- Capture and inject packets
+- Analyze and build packets
+- Easy-to-use API
+
+## Installation
+
+You can install the package via NuGet Package Manager:
+
+
+## Usage
+
+Here is a simple example of how to use SharpPcap:
+
+```cs
+using SharpPcap;
+using PacketDotNet;
+
+
+// List available devices
+var devices = CaptureDeviceList.Instance;
+foreach (var dev in devices) {
+ Console.WriteLine($"{dev.Name} - {dev.Description}");
+}
+
+// Open the first device
+var device = devices[0];
+device.Open();
+
+// Capture packets
+device.OnPacketArrival += new PacketArrivalEventHandler(Device_OnPacketArrival);
+device.StartCapture();
+
+Console.WriteLine("Press any key to stop...");
+Console.ReadKey();
+
+device.StopCapture();
+device.Close();
+
+
+static void Device_OnPacketArrival(object sender, CaptureEventArgs e)
+{
+ var packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
+ Console.WriteLine(packet.ToString());
+}
+
+```
+
+## License
+
+This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
+
+## TODO
+- Nullability
+- replace [DllImport] with [ImportLibrary]
\ No newline at end of file
diff --git a/SharpPcap/README_StaticLinking.md b/SharpPcap/README_StaticLinking.md
new file mode 100644
index 00000000..76854eda
--- /dev/null
+++ b/SharpPcap/README_StaticLinking.md
@@ -0,0 +1,79 @@
+# Lansweeper SharpPcap
+
+This is a fork of the original SharpPcap project, which is a cross-platform packet capture framework for the .NET environment.
+The original project can be found [here](https://github.com/dotpcap/sharppcap)
+
+This fork is maintained by Lansweeper and can be found [here](https://github.com/Lansweeper/sharppcap)
+
+> This is the a special version to support static linking on UNIX. For the default version with dynamic linking, see `Lansweeper.SharpPcap`.
+
+## Changes to the original project
+- Allow for AoT compilation
+- Added support for ARM64
+- Better abstractions and better testability
+- Removed netstandard2.0 support
+
+SharpPcap is a cross-platform (Windows, Mac, Linux) packet capture framework for the .NET environment.
+It provides an API for capturing, injecting, analyzing, and building packets using any .NET language such as C# and VB.NET.
+
+## Features
+
+- Cross-platform support (Windows, Mac, Linux)
+- Capture and inject packets
+- Analyze and build packets
+- Easy-to-use API
+
+## Installation
+
+You can install the package via NuGet Package Manager:
+
+
+## Usage
+
+Here is a simple example of how to use SharpPcap:
+
+```cs
+using SharpPcap;
+using PacketDotNet;
+
+
+// List available devices
+var devices = CaptureDeviceList.Instance;
+foreach (var dev in devices) {
+ Console.WriteLine($"{dev.Name} - {dev.Description}");
+}
+
+// Open the first device
+var device = devices[0];
+device.Open();
+
+// Capture packets
+device.OnPacketArrival += new PacketArrivalEventHandler(Device_OnPacketArrival);
+device.StartCapture();
+
+Console.WriteLine("Press any key to stop...");
+Console.ReadKey();
+
+device.StopCapture();
+device.Close();
+
+
+static void Device_OnPacketArrival(object sender, CaptureEventArgs e)
+{
+ var packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
+ Console.WriteLine(packet.ToString());
+}
+
+```
+
+## Documentation
+
+For more detailed documentation, please visit the [project's GitHub page](https://github.com/Lansweeper/sharppcap).
+
+## License
+
+This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
+
+## TODO
+- Nullability
+- replace [DllImport] with [ImportLibrary]
\ No newline at end of file
diff --git a/SharpPcap/SharpPcap.csproj b/SharpPcap/SharpPcap.csproj
index f627c290..40d913d8 100644
--- a/SharpPcap/SharpPcap.csproj
+++ b/SharpPcap/SharpPcap.csproj
@@ -8,7 +8,7 @@ SPDX-License-Identifier: MIT
net8.0
- 10.0.0-alpha
+ 10.0.0-beta
Lansweeper.SharpPcap
Lansweeper
Lansweeper SharpPcap
@@ -28,11 +28,20 @@ SPDX-License-Identifier: MIT
It provides an API for capturing, injecting, analyzing and building packets using any .NET language such as C# and VB.NET.
MIT
+ README.md
true
true
true
true
+
+
+ STATIC_LINKING
+ Lansweeper.SharpPcap.StaticLinking
+ $(PackageVersion)
+ README_StaticLinking.md
+
+
From 8dfeea10ef9003bd5f09b02046b1179627a6c6a5 Mon Sep 17 00:00:00 2001
From: Lander Verhack
Date: Wed, 15 Jan 2025 15:46:22 +0100
Subject: [PATCH 53/53] temp disable master only, to test NuGets
---
.circleci/config.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 7bd4fa53..c6082fe4 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -167,9 +167,9 @@ workflows:
- nuget-prepare
context:
- lec-github-packages-rw
- filters:
- branches:
- only: master
+ # filters:
+ # branches:
+ # only: master
run-daily-tests:
triggers: