From cf43b58df9b7a2aebd0463e54ae9628de47e1c92 Mon Sep 17 00:00:00 2001 From: Ayoub Kaanich Date: Sun, 2 Mar 2025 03:27:32 +0100 Subject: [PATCH] Use generic Marshal.SizeOf --- Directory.Build.props | 1 - SharpPcap/LibPcap/BpfProgram.cs | 2 +- SharpPcap/LibPcap/PcapStatistics.cs | 4 ++-- 3 files changed, 3 insertions(+), 4 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..30b61462 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