Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Oct 24, 2022
1 parent 1c1aa8e commit bba5d53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
9 changes: 7 additions & 2 deletions WindivertDotnet.Test/TcpHeaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void WriteTest()
Ack = true,
Fin = true,
Psh = true,
Syn = true,
Urg = true,
Rst = true,

Expand All @@ -57,7 +56,7 @@ public void WriteTest()
Assert.True(header.Flags.HasFlag(TcpFlag.Psh));
Assert.True(header.Flags.HasFlag(TcpFlag.Rst));
Assert.True(header.Flags.HasFlag(TcpFlag.Fin));
Assert.True(header.Flags.HasFlag(TcpFlag.Syn));
Assert.False(header.Flags.HasFlag(TcpFlag.Syn));

Assert.Equal(2U, header.AckNum);
Assert.Equal(3, header.Checksum);
Expand All @@ -68,6 +67,12 @@ public void WriteTest()
Assert.Equal(12U, header.SeqNum);
Assert.Equal(13, header.SrcPort);
Assert.Equal(16, header.Window);


header.Flags &= ~(TcpFlag.Fin | TcpFlag.Rst);
Assert.False(header.Flags.HasFlag(TcpFlag.Rst));
Assert.False(header.Flags.HasFlag(TcpFlag.Fin));

}
}
}
24 changes: 18 additions & 6 deletions WindivertDotnet/TcpHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public byte HdrLength
public bool Fin
{
get => this.Flags.HasFlag(TcpFlag.Fin);
set => this.Flags |= TcpFlag.Fin;
set => this.SetFlag(TcpFlag.Fin, value);
}

/// <summary>
Expand All @@ -103,7 +103,7 @@ public bool Fin
public bool Syn
{
get => this.Flags.HasFlag(TcpFlag.Syn);
set => this.Flags |= TcpFlag.Syn;
set => this.SetFlag(TcpFlag.Syn, value);
}

/// <summary>
Expand All @@ -112,7 +112,7 @@ public bool Syn
public bool Rst
{
get => this.Flags.HasFlag(TcpFlag.Rst);
set => this.Flags |= TcpFlag.Rst;
set => this.SetFlag(TcpFlag.Rst, value);
}

/// <summary>
Expand All @@ -121,7 +121,7 @@ public bool Rst
public bool Psh
{
get => this.Flags.HasFlag(TcpFlag.Psh);
set => this.Flags |= TcpFlag.Psh;
set => this.SetFlag(TcpFlag.Psh, value);
}

/// <summary>
Expand All @@ -130,7 +130,7 @@ public bool Psh
public bool Ack
{
get => this.Flags.HasFlag(TcpFlag.Ack);
set => this.Flags |= TcpFlag.Ack;
set => this.SetFlag(TcpFlag.Ack, value);
}

/// <summary>
Expand All @@ -139,7 +139,7 @@ public bool Ack
public bool Urg
{
get => this.Flags.HasFlag(TcpFlag.Urg);
set => this.Flags |= TcpFlag.Urg;
set => this.SetFlag(TcpFlag.Urg, value);
}

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Expand Down Expand Up @@ -177,5 +177,17 @@ public ushort UrgPtr
get => BinaryPrimitives.ReverseEndianness(urgPtr);
set => urgPtr = BinaryPrimitives.ReverseEndianness(value);
}

private void SetFlag(TcpFlag flag, bool value)
{
if (value)
{
this.Flags |= flag;
}
else
{
this.Flags &= ~flag;
}
}
}
}

0 comments on commit bba5d53

Please sign in to comment.