diff --git a/WindivertDotnet.Test/WinDivertAddressTest.cs b/WindivertDotnet.Test/WinDivertAddressTest.cs index 111b1c7..52fcd49 100644 --- a/WindivertDotnet.Test/WinDivertAddressTest.cs +++ b/WindivertDotnet.Test/WinDivertAddressTest.cs @@ -12,6 +12,9 @@ public void CloneTest() using var clone = addr.Clone(); Assert.Equal(addr.Flags, clone.Flags); + + addr.Flags = WinDivertAddressFlag.IPv6; + Assert.NotEqual(addr.Flags, clone.Flags); } } } diff --git a/WindivertDotnet/WinDivertPacket.cs b/WindivertDotnet/WinDivertPacket.cs index 4f67645..cf224e6 100644 --- a/WindivertDotnet/WinDivertPacket.cs +++ b/WindivertDotnet/WinDivertPacket.cs @@ -60,7 +60,7 @@ public int Length /// /// 最大容量 public WinDivertPacket(int capacity = MTU_MAX) - : this(MemoryNative.AllocZeroed(capacity), capacity, ownsHandle: true) + : base(ownsHandle: true) { this.Capacity = capacity; this.handle = MemoryNative.AllocZeroed(capacity); @@ -69,14 +69,14 @@ public WinDivertPacket(int capacity = MTU_MAX) /// /// WinDivert的数据包 /// - /// - /// - /// - private unsafe WinDivertPacket(IntPtr handle, int capacity, bool ownsHandle) - : base(ownsHandle) + /// 外部创建的句柄 + /// 字节长度 + private unsafe WinDivertPacket(IntPtr handle, int length) + : base(ownsHandle: false) { this.handle = handle; - this.Capacity = capacity; + this.length = length; + this.Capacity = length; } /// @@ -119,11 +119,7 @@ public unsafe Span GetSpan(int offset, int count) public unsafe WinDivertPacket Slice(int offset, int count) { var pointer = this.GetPointer(offset, count); - var handle = new IntPtr(pointer); - return new WinDivertPacket(handle, count, ownsHandle: false) - { - length = count - }; + return new WinDivertPacket(new IntPtr(pointer), count); } @@ -134,6 +130,7 @@ public unsafe WinDivertPacket Slice(int offset, int count) /// /// /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] private unsafe void* GetPointer(int offset, int count) { if (offset < 0 || offset > this.Capacity) @@ -238,6 +235,7 @@ public bool CalcLoopbackFlag(WinDivertAddress addr) /// /// /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] private unsafe bool TryParseIPAddress( [MaybeNullWhen(false)] out IPAddress srcAddr, [MaybeNullWhen(false)] out IPAddress dstAddr) diff --git a/WindivertDotnet/WindivertDotnet.csproj b/WindivertDotnet/WindivertDotnet.csproj index 06cedc3..3233dde 100644 --- a/WindivertDotnet/WindivertDotnet.csproj +++ b/WindivertDotnet/WindivertDotnet.csproj @@ -1,7 +1,7 @@  - 1.1.0 + 1.1.1 netcoreapp3.1;net6.0 enable CA2012;IDE0079