From e416f7ef920a679e0d305c611d9e24cd76f4bc65 Mon Sep 17 00:00:00 2001 From: xljiulang <366193849@qq.com> Date: Thu, 20 Oct 2022 20:34:32 +0800 Subject: [PATCH] WinDivertFlag.Sniff | WinDivertFlag.RecvOnly --- WindivertDotnet/WinDivert.cs | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/WindivertDotnet/WinDivert.cs b/WindivertDotnet/WinDivert.cs index 521494a..0e7324a 100644 --- a/WindivertDotnet/WinDivert.cs +++ b/WindivertDotnet/WinDivert.cs @@ -107,7 +107,10 @@ public WinDivert(Filter filter, WinDivertLayer layer, short priority = 0, WinDiv public WinDivert(string filter, WinDivertLayer layer, short priority = 0, WinDivertFlag flags = WinDivertFlag.None) : base(ownsHandle: true) { - AutoFlagsWhenNone(ref flags, layer); + if (layer != WinDivertLayer.Network && flags == WinDivertFlag.None) + { + flags = WinDivertFlag.Sniff | WinDivertFlag.RecvOnly; + } var compileFilter = WindivertDotnet.Filter.Compile(filter, layer); @@ -136,31 +139,6 @@ public WinDivert(string filter, WinDivertLayer layer, short priority = 0, WinDiv this.Version = this.GetVersion(); } - /// - /// 返回当指示为None时对应的默认值 - /// - /// - /// - /// - private static void AutoFlagsWhenNone(ref WinDivertFlag flags, WinDivertLayer layer) - { - if (flags == WinDivertFlag.None) - { - switch (layer) - { - case WinDivertLayer.Socket: - flags = WinDivertFlag.RecvOnly; - break; - - case WinDivertLayer.Flow: - case WinDivertLayer.Reflect: - case WinDivertLayer.Forward: - flags = WinDivertFlag.Sniff | WinDivertFlag.RecvOnly; - break; - } - } - } - /// /// 获取版本信息 ///