This commit is contained in:
黄思敏 2022-08-29 09:11:46 +08:00
parent 8b8f55d573
commit b896363b34
2 changed files with 16 additions and 6 deletions

View File

@ -131,9 +131,11 @@ func (nc *NetCard) Run() {
func NewNetCard() *NetCard { func NewNetCard() *NetCard {
config := water.Config{ config := water.Config{
DeviceType: water.TUN, DeviceType: water.TAP,
PlatformSpecificParams: water.PlatformSpecificParams{
Name: "stun",
},
} }
config.Name = "stun"
ifce, err := water.New(config) ifce, err := water.New(config)
if err != nil { if err != nil {

16
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"log" "log"
"os/exec" "os/exec"
@ -17,15 +18,22 @@ func init() {
//go:generate bash -c "protoc --go_out=plugins=grpc:. proto/*.proto" //go:generate bash -c "protoc --go_out=plugins=grpc:. proto/*.proto"
func main() { func main() {
// testmain() testmain()
NewNetCard().Run() // NewNetCard().Run()
} }
var (
flagAddr = flag.String("addr", "", "addr set")
)
func testmain() { func testmain() {
flag.Parse()
var a chan bool = make(chan bool) var a chan bool = make(chan bool)
go func() { go func() {
<-a <-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) log.Println(cmdstr)
cmd := strings.Split(cmdstr, " ") cmd := strings.Split(cmdstr, " ")
err := exec.Command(cmd[0], cmd[1:]...).Run() err := exec.Command(cmd[0], cmd[1:]...).Run()
@ -42,7 +50,7 @@ func testmain() {
}() }()
config := water.Config{ config := water.Config{
DeviceType: water.TUN, DeviceType: water.TAP,
} }
config.Name = "stun" config.Name = "stun"