diff --git a/WindivertDotnet.Test/TcpHeaderTest.cs b/WindivertDotnet.Test/TcpHeaderTest.cs index 2271099..c4c8a06 100644 --- a/WindivertDotnet.Test/TcpHeaderTest.cs +++ b/WindivertDotnet.Test/TcpHeaderTest.cs @@ -35,7 +35,6 @@ public void WriteTest() Ack = true, Fin = true, Psh = true, - Syn = true, Urg = true, Rst = true, @@ -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); @@ -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)); + } } } diff --git a/WindivertDotnet/TcpHeader.cs b/WindivertDotnet/TcpHeader.cs index f996ab7..1ec80df 100644 --- a/WindivertDotnet/TcpHeader.cs +++ b/WindivertDotnet/TcpHeader.cs @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// @@ -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)] @@ -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; + } + } } }