过滤非loopback ip #127

This commit is contained in:
陈国伟 2022-03-01 16:58:27 +08:00
parent 519c4d8e80
commit ba56d2370f
2 changed files with 12 additions and 2 deletions

View File

@ -71,6 +71,7 @@ namespace FastGithub.PacketIntercept.Tcp
while (cancellationToken.IsCancellationRequested == false)
{
winDivertAddress.Reset();
if (WinDivert.WinDivertRecv(handle, winDivertBuffer, ref winDivertAddress, ref packetLength) == false)
{
throw new Win32Exception();
@ -100,6 +101,15 @@ namespace FastGithub.PacketIntercept.Tcp
unsafe private void ModifyTcpPacket(WinDivertBuffer winDivertBuffer, ref WinDivertAddress winDivertAddress, ref uint packetLength)
{
var packet = WinDivert.WinDivertHelperParsePacket(winDivertBuffer, packetLength);
if (packet.IPv4Header != null && packet.IPv4Header->SrcAddr.Equals(IPAddress.Loopback) == false)
{
return;
}
if (packet.IPv6Header != null && packet.IPv6Header->SrcAddr.Equals(IPAddress.IPv6Loopback) == false)
{
return;
}
if (packet.TcpHeader->DstPort == oldServerPort)
{
packet.TcpHeader->DstPort = this.newServerPort;

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31320.298
# Visual Studio Version 17
VisualStudioVersion = 17.1.32203.90
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub", "FastGithub\FastGithub.csproj", "{C1099390-6103-4917-A740-A3002B542FE0}"
EndProject