Skip to content

Commit

Permalink
移除ApplyLengthToIPHeader方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Oct 20, 2022
1 parent 7da68ed commit fae4850
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 43 deletions.
17 changes: 2 additions & 15 deletions WindivertDotnet.Test/WinDivertPacketTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Versioning;
using Xunit;

namespace WindivertDotnet.Test
{
[SupportedOSPlatform("windows")]
public class WinDivertPacketTest
{
[Fact]
Expand Down Expand Up @@ -80,21 +82,6 @@ public void CalcOutboundFlagTest()
Assert.Equal(router.IsOutbound, addr.Flags.HasFlag(WinDivertAddressFlag.Outbound));
}

[Fact]
public unsafe void ApplyLengthToIPHeaderTest()
{
var router = new WinDivertRouter(IPAddress.Loopback);
using var packet = new WinDivertPacket();

var ipv4Header = CreateIPV4Header(router);
ipv4Header.Length = 0;
packet.GetWriter().Write(ipv4Header);

packet.ApplyLengthToIPHeader();
var result = packet.GetParseResult();

Assert.Equal(sizeof(IPV4Header), result.IPV4Header->Length);
}

private static IPV4Header CreateIPV4Header(WinDivertRouter router)
{
Expand Down
28 changes: 0 additions & 28 deletions WindivertDotnet/WinDivertPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,34 +226,6 @@ private unsafe bool TryParseIPAddress(
return false;
}

/// <summary>
/// 将属性Length值应用到IPHeader
/// 当包的负载数据长度变化后使用此方法很方便
/// </summary>
/// <returns></returns>
public unsafe bool ApplyLengthToIPHeader()
{
if (this.length > 1)
{
var ptr = this.handle.ToPointer();
var version = Unsafe.Read<byte>(ptr) >> 4;

if (version == 4 && this.length >= sizeof(IPV4Header))
{
((IPV4Header*)ptr)->Length = (ushort)this.length;
return true;
}

if (version == 6 && this.length >= sizeof(IPV6Header))
{
((IPV6Header*)ptr)->Length = (ushort)(this.length - sizeof(IPV6Header));
return true;
}
}

return false;
}

/// <summary>
/// ttl减1
/// </summary>
Expand Down

0 comments on commit fae4850

Please sign in to comment.