From f67fe2e46f0151d0d93df90def5bf163293ce5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Fri, 24 Sep 2021 10:45:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=A5=E6=9F=84=E6=97=A0=E6=95=88=E6=97=B6?= =?UTF-8?q?=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.PacketIntercept/Dns/DnsInterceptor.cs | 9 +++++++-- FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs index 7ed388b..7015b75 100644 --- a/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs +++ b/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs @@ -23,6 +23,7 @@ namespace FastGithub.PacketIntercept.Dns [SupportedOSPlatform("windows")] sealed class DnsInterceptor : IDnsInterceptor { + private const int ERROR_INVALID_HANDLE = 0x6; private const string DNS_FILTER = "udp.DstPort == 53"; private readonly FastGithubConfig fastGithubConfig; private readonly ILogger logger; @@ -97,8 +98,12 @@ namespace FastGithub.PacketIntercept.Dns } else { - var exception = new Win32Exception(Marshal.GetLastWin32Error()); - this.logger.LogError(exception.Message); + var errorCode = Marshal.GetLastWin32Error(); + this.logger.LogError(new Win32Exception(errorCode).Message); + if (errorCode == ERROR_INVALID_HANDLE) + { + break; + } } } } diff --git a/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs b/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs index d342421..2fd52ae 100644 --- a/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs +++ b/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs @@ -17,6 +17,7 @@ namespace FastGithub.PacketIntercept.Tcp [SupportedOSPlatform("windows")] abstract class TcpInterceptor : ITcpInterceptor { + private const int ERROR_INVALID_HANDLE = 0x6; private readonly string filter; private readonly ushort oldServerPort; private readonly ushort newServerPort; @@ -82,8 +83,12 @@ namespace FastGithub.PacketIntercept.Tcp } else { - var exception = new Win32Exception(Marshal.GetLastWin32Error()); - this.logger.LogError(exception.Message); + var errorCode = Marshal.GetLastWin32Error(); + this.logger.LogError(new Win32Exception(errorCode).Message); + if (errorCode == ERROR_INVALID_HANDLE) + { + break; + } } } }