mirror of
https://github.com/netchx/netch.git
synced 2026-04-25 21:39:41 +08:00
Update TUNController (tun2socks.bin)
This commit is contained in:
74
Netch/Controllers/TUNInterop.cs
Normal file
74
Netch/Controllers/TUNInterop.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Netch.Utils;
|
||||
|
||||
namespace Netch.Controllers
|
||||
{
|
||||
public class TUNInterop
|
||||
{
|
||||
public enum NameList
|
||||
{
|
||||
TYPE_BYPBIND,
|
||||
TYPE_BYPLIST,
|
||||
TYPE_DNSADDR,
|
||||
TYPE_ADAPMTU,
|
||||
TYPE_TCPREST,
|
||||
TYPE_TCPTYPE,
|
||||
TYPE_TCPHOST,
|
||||
TYPE_TCPUSER,
|
||||
TYPE_TCPPASS,
|
||||
TYPE_TCPMETH,
|
||||
TYPE_TCPPROT,
|
||||
TYPE_TCPPRPA,
|
||||
TYPE_TCPOBFS,
|
||||
TYPE_TCPOBPA,
|
||||
TYPE_UDPREST,
|
||||
TYPE_UDPTYPE,
|
||||
TYPE_UDPHOST,
|
||||
TYPE_UDPUSER,
|
||||
TYPE_UDPPASS,
|
||||
TYPE_UDPMETH,
|
||||
TYPE_UDPPROT,
|
||||
TYPE_UDPPRPA,
|
||||
TYPE_UDPOBFS,
|
||||
TYPE_UDPOBPA
|
||||
}
|
||||
|
||||
public bool Dial(NameList name, string value)
|
||||
{
|
||||
Logging.Debug($"Dial {name} {value}");
|
||||
return tun_dial(name, Encoding.UTF8.GetBytes(value));
|
||||
}
|
||||
|
||||
public bool Init()
|
||||
{
|
||||
return tun_init();
|
||||
}
|
||||
|
||||
public bool Free()
|
||||
{
|
||||
return tun_free();
|
||||
}
|
||||
|
||||
private const string tun2socks_bin = "tun2socks.bin";
|
||||
|
||||
[DllImport(tun2socks_bin, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tun_dial(NameList name, byte[] value);
|
||||
|
||||
[DllImport(tun2socks_bin, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tun_init();
|
||||
|
||||
[DllImport(tun2socks_bin, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool tun_free();
|
||||
|
||||
[DllImport(tun2socks_bin, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tun_luid();
|
||||
|
||||
[DllImport(tun2socks_bin, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tun_getUP();
|
||||
|
||||
[DllImport(tun2socks_bin, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong tun_getDL();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user