소스 검색

过滤非loopback ip #127

陈国伟 3 년 전
부모
커밋
ba56d2370f
2개의 변경된 파일12개의 추가작업 그리고 2개의 파일을 삭제
  1. 10 0
      FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs
  2. 2 2
      FastGithub.sln

+ 10 - 0
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;

+ 2 - 2
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