句柄无效时退出

This commit is contained in:
陈国伟 2021-09-24 10:45:22 +08:00
parent f2b248f18d
commit f67fe2e46f
2 changed files with 14 additions and 4 deletions

View File

@ -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<DnsInterceptor> 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;
}
}
}
}

View File

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