From b896363b3434d0cafa104ee2759240b26862a730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Mon, 29 Aug 2022 09:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device.go | 6 ++++-- main.go | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/device.go b/device.go index 3ba3255..337cd5b 100644 --- a/device.go +++ b/device.go @@ -131,9 +131,11 @@ func (nc *NetCard) Run() { func NewNetCard() *NetCard { config := water.Config{ - DeviceType: water.TUN, + DeviceType: water.TAP, + PlatformSpecificParams: water.PlatformSpecificParams{ + Name: "stun", + }, } - config.Name = "stun" ifce, err := water.New(config) if err != nil { diff --git a/main.go b/main.go index bef35ea..ba1d5eb 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "log" "os/exec" @@ -17,15 +18,22 @@ func init() { //go:generate bash -c "protoc --go_out=plugins=grpc:. proto/*.proto" func main() { - // testmain() - NewNetCard().Run() + testmain() + // NewNetCard().Run() } +var ( + flagAddr = flag.String("addr", "", "addr set") +) + func testmain() { + + flag.Parse() + var a chan bool = make(chan bool) go func() { <-a - cmdstr := fmt.Sprintf("ip addr add %s dev stun", "10.10.10.111") + cmdstr := fmt.Sprintf("ip addr add %s dev stun", *flagAddr) log.Println(cmdstr) cmd := strings.Split(cmdstr, " ") err := exec.Command(cmd[0], cmd[1:]...).Run() @@ -42,7 +50,7 @@ func testmain() { }() config := water.Config{ - DeviceType: water.TUN, + DeviceType: water.TAP, } config.Name = "stun"