This commit is contained in:
Shiming Zhang
2022-03-13 18:55:24 +08:00
parent 933f75497c
commit d8b087146a
3 changed files with 29 additions and 3 deletions

View File

@@ -24,12 +24,13 @@ var (
)
func init() {
iface, _ := control.DefaultInterfaceName()
flag.IntVar(&mark, "fwmark", 0, "Set firewall MARK (Linux only)")
flag.IntVar(&conf.MTU, "mtu", 0, "Set device maximum transmission unit (MTU)")
flag.StringVar(&conf.Device, "device", "", "Use this device")
flag.StringVar(&conf.Name, "name", "", "Use this device name")
flag.StringVar(&route, "route", "10.0.0.0/8", "Set the route")
flag.StringVar(&interfaceName, "interface", "", "Use network INTERFACE (Linux/MacOS only)")
flag.StringVar(&interfaceName, "interface", iface, "Use network INTERFACE (Linux/MacOS only)")
flag.Parse()
}
@@ -60,7 +61,6 @@ func main() {
conf.Logger = logger
conf.Dialer = WrapDialerFunc(func(ctx context.Context, network, address string) (net.Conn, error) {
logger.Println("Dial", network, address)
return dialer.DialContext(ctx, network, "www.baidu.com:80")
return dialer.DialContext(ctx, network, address)
})
conf.ListenPacket = &listenConfig

26
control/interface_name.go Normal file
View File

@@ -0,0 +1,26 @@
package control
import (
"net"
"strings"
)
func DefaultInterfaceName() (string, error) {
ifaces, err := net.Interfaces()
if err != nil {
return "", err
}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 {
continue
}
if iface.Flags&net.FlagBroadcast == 0 {
continue
}
if strings.HasPrefix(iface.Name, "en") || strings.HasPrefix(iface.Name, "eth") {
return iface.Name, nil
}
}
return "", nil
}

2
go.mod
View File

@@ -5,7 +5,6 @@ go 1.17
require (
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224
golang.zx2c4.com/wireguard v0.0.0-20220202223031-3b95c81cc178
gvisor.dev/gvisor v0.0.0-20220208035940-56a131734b85
)
@@ -13,4 +12,5 @@ require (
require (
github.com/google/btree v1.0.1 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
)