Skip to content

Commit

Permalink
Use MemoryMarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
kayoub5 committed Jul 30, 2024
1 parent b3a1ea5 commit 0787346
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion SharpPcap/Tunneling/WinTap/WinTapDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ internal static void ConfigureDhcp(SafeFileHandle handle, IPAddress ip, IPAddres
internal static void SetMediaStatus(SafeFileHandle handle, bool connected)
{
int value = connected ? 1 : 0;
Span<byte> inBuffer = BitConverter.GetBytes(value);
Span<byte> inBuffer = stackalloc byte[4];
Span<byte> outBuffer = stackalloc byte[4];
#if NET8_0_OR_GREATER
MemoryMarshal.Write(inBuffer, in value);
#else
MemoryMarshal.Write(inBuffer, ref value);
#endif
TapControl(handle, TapIoControl.SetMediaStatus, inBuffer, ref outBuffer);
}

Expand Down

0 comments on commit 0787346

Please sign in to comment.