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; + } } } }