Skip to content

Commit

Permalink
WinDivertFlag.Sniff | WinDivertFlag.RecvOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Oct 20, 2022
1 parent 2478512 commit e416f7e
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions WindivertDotnet/WinDivert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -136,31 +139,6 @@ public WinDivert(string filter, WinDivertLayer layer, short priority = 0, WinDiv
this.Version = this.GetVersion();
}

/// <summary>
/// 返回当指示为None时对应的默认值
/// </summary>
/// <param name="flags"></param>
/// <param name="layer"></param>
/// <returns></returns>
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;
}
}
}

/// <summary>
/// 获取版本信息
/// </summary>
Expand Down

0 comments on commit e416f7e

Please sign in to comment.