Skip to content

Commit

Permalink
Use generic Marshal.SizeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
kayoub5 committed Mar 2, 2025
1 parent eaa318a commit cf43b58
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ SPDX-License-Identifier: MIT
<Deterministic>true</Deterministic>
<DebugType>full</DebugType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion SharpPcap/LibPcap/BpfProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PcapUnmanagedStructures.bpf_program>());
SetHandle(bpfProgram);
}

Expand Down
4 changes: 2 additions & 2 deletions SharpPcap/LibPcap/PcapStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PcapUnmanagedStructures.pcap_stat_unix>());
}
else
{
// allocate memory for the struct
stat = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_stat_windows)));
stat = Marshal.AllocHGlobal(Marshal.SizeOf<PcapUnmanagedStructures.pcap_stat_windows>());
}

// retrieve the stats
Expand Down

0 comments on commit cf43b58

Please sign in to comment.