mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-25 01:31:06 +08:00
update main
This commit is contained in:
@@ -26,15 +26,6 @@ const MTU = 1500
|
|||||||
var (
|
var (
|
||||||
version = "unknown version"
|
version = "unknown version"
|
||||||
description = "A tun2socks implementation written in Go."
|
description = "A tun2socks implementation written in Go."
|
||||||
|
|
||||||
args = new(CmdArgs)
|
|
||||||
|
|
||||||
handlerCreator func()
|
|
||||||
postFlagsInitFn []func()
|
|
||||||
|
|
||||||
lwipWriter io.Writer
|
|
||||||
fakeDns dns.FakeDns
|
|
||||||
sessionStater stats.SessionStater
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdArgs struct {
|
type CmdArgs struct {
|
||||||
@@ -64,6 +55,17 @@ type CmdArgs struct {
|
|||||||
StatsAddr *string
|
StatsAddr *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
args = new(CmdArgs)
|
||||||
|
|
||||||
|
handlerCreator func()
|
||||||
|
postFlagsInitFn []func()
|
||||||
|
|
||||||
|
lwipWriter io.Writer
|
||||||
|
fakeDns dns.FakeDns
|
||||||
|
sessionStater stats.SessionStater
|
||||||
|
)
|
||||||
|
|
||||||
func addPostFlagsInitFn(fn func()) {
|
func addPostFlagsInitFn(fn func()) {
|
||||||
postFlagsInitFn = append(postFlagsInitFn, fn)
|
postFlagsInitFn = append(postFlagsInitFn, fn)
|
||||||
}
|
}
|
||||||
@@ -75,25 +77,24 @@ func registerHandlerCreator(creator func()) {
|
|||||||
handlerCreator = creator
|
handlerCreator = creator
|
||||||
}
|
}
|
||||||
|
|
||||||
func showVersion() {
|
func init() {
|
||||||
fmt.Println("Go-tun2socks", version)
|
|
||||||
fmt.Println(description)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
args.Version = flag.Bool("version", false, "Print version")
|
args.Version = flag.Bool("version", false, "Print version")
|
||||||
args.DelayICMP = flag.Int("delayICMP", 1, "Delay ICMP packets for a short period of time, in milliseconds")
|
args.LogLevel = flag.String("loglevel", "info", "Logging level. (info, warning, error, debug, silent)")
|
||||||
args.TunName = flag.String("tunName", "tun0", "TUN interface name")
|
args.TunName = flag.String("tunName", "tun0", "TUN interface name")
|
||||||
args.TunAddr = flag.String("tunAddr", "240.0.0.2", "TUN interface address")
|
args.TunAddr = flag.String("tunAddr", "240.0.0.2", "TUN interface address")
|
||||||
args.TunGw = flag.String("tunGw", "240.0.0.1", "TUN interface gateway")
|
args.TunGw = flag.String("tunGw", "240.0.0.1", "TUN interface gateway")
|
||||||
args.TunMask = flag.String("tunMask", "255.255.255.0", "TUN interface netmask, it should be a prefix length (a number) for IPv6 address")
|
args.TunMask = flag.String("tunMask", "255.255.255.0", "TUN interface netmask, it should be a prefix length (a number) for IPv6 address")
|
||||||
args.TunDns = flag.String("tunDns", "1.1.1.1", "DNS resolvers for TUN interface (Windows Only)")
|
args.TunDns = flag.String("tunDns", "1.1.1.1", "DNS resolvers for TUN interface (Windows Only)")
|
||||||
args.LogLevel = flag.String("loglevel", "info", "Logging level. (info, warning, error, debug, silent)")
|
args.DelayICMP = flag.Int("delayICMP", 1, "Delay ICMP packets for a short period of time, in milliseconds")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Parse args
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *args.Version {
|
if *args.Version {
|
||||||
showVersion()
|
fmt.Println("Go-tun2socks", version)
|
||||||
|
fmt.Println(description)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/xjasonlyu/tun2socks/common/log"
|
"github.com/xjasonlyu/tun2socks/common/log"
|
||||||
"github.com/xjasonlyu/tun2socks/core"
|
"github.com/xjasonlyu/tun2socks/core"
|
||||||
"github.com/xjasonlyu/tun2socks/proxy/socks"
|
"github.com/xjasonlyu/tun2socks/proxy/socks"
|
||||||
"net"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
args.ProxyServer = flag.String("proxyServer", "1.2.3.4:1087", "Proxy server address")
|
args.ProxyServer = flag.String("proxyServer", "", "Proxy server address")
|
||||||
args.UdpTimeout = flag.Duration("udpTimeout", 60*time.Second, "UDP session timeout")
|
args.UdpTimeout = flag.Duration("udpTimeout", 60*time.Second, "UDP session timeout")
|
||||||
|
|
||||||
registerHandlerCreator(func() {
|
registerHandlerCreator(func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user