From ba56d2370f129e2d73df01290e1291cfebd399b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Tue, 1 Mar 2022 16:58:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=9D=9Eloopback=20ip=20#127?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs | 10 ++++++++++ FastGithub.sln | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs b/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs index f25b0c6..1a41d1e 100644 --- a/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs +++ b/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs @@ -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; diff --git a/FastGithub.sln b/FastGithub.sln index 45ccc94..2be28f9 100644 --- a/FastGithub.sln +++ b/FastGithub.sln @@ -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