From c505e2abbbf2390913771d87c8f5c22ee3747642 Mon Sep 17 00:00:00 2001 From: Connection Refused Date: Fri, 26 Mar 2021 19:31:42 +0800 Subject: [PATCH] Update TUNController --- Netch/Controllers/TUNController.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Netch/Controllers/TUNController.cs b/Netch/Controllers/TUNController.cs index 374e35e6..38a97b01 100644 --- a/Netch/Controllers/TUNController.cs +++ b/Netch/Controllers/TUNController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -66,14 +67,7 @@ namespace Netch.Controllers StartInstanceAuto(parameter.ToString()); _tunAdapter = new TunAdapter(); - /* - InitializeUnicastIpAddressEntry(out var addr_row); - CreateUnicastIpAddressEntry(ref addr_row); - */ - - Utils.Utils.ProcessRunHiddenAsync("netsh", "interface ipv4 add address aioCloud 100.64.0.100 255.255.255.0").Wait(); - Utils.Utils.ProcessRunHiddenAsync("route", "print -4", false).Wait(); - + NativeMethods.CreateUnicastIP((int)AddressFamily.InterNetwork, "100.64.0.100", 24, _tunAdapter.InterfaceIndex); SetupRouteTable(mode); } @@ -232,14 +226,14 @@ namespace Netch.Controllers { case Action.Create: - result = NativeMethods.CreateRoute((int) ADDRESS_FAMILY.AF_INET, network, cidr, gateway, index, metric); + result = NativeMethods.CreateRoute((int)AddressFamily.InterNetwork, network, cidr, gateway, index, metric); #if DEBUG Console.WriteLine($"CreateRoute(\"{network}\", {cidr}, \"{gateway}\", {index}, {metric})"); #endif ipList.Add(ipNetwork); break; case Action.Delete: - result = NativeMethods.DeleteRoute((int) ADDRESS_FAMILY.AF_INET, network, cidr, gateway, index, metric); + result = NativeMethods.DeleteRoute((int)AddressFamily.InterNetwork, network, cidr, gateway, index, metric); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null);