This commit is contained in:
黄思敏 2022-08-25 10:24:31 +08:00
parent 95834d2324
commit f8d4727c2b

14
tap.go
View File

@ -3,7 +3,9 @@ package main
import (
"context"
"log"
"os/exec"
gen "slimming/proto/gen"
"strings"
"time"
"github.com/songgao/packets/ethernet"
@ -67,6 +69,17 @@ func (nc *NetCard) Run() {
go nc.runRead()
go nc.runWrite()
// go nc.cli.run()
time.Sleep(time.Second)
cmd := strings.Split("addr add 10.10.10.10/24 dev stap", " ")
err := exec.Command(cmd[0], cmd[1:]...).Run()
if err != nil {
panic(err)
}
cmd = strings.Split("ip link set dev stap up", " ")
err = exec.Command(cmd[0], cmd[1:]...).Run()
if err != nil {
panic(err)
}
nc.server.run()
}
@ -109,6 +122,7 @@ func (nc *NetCard) runRead() {
framesBytes = append(framesBytes, []byte(rframe))
}
println(len(framesBytes))
if len(framesBytes) > 0 {
if nc.cli.conn == nil {
nc.cli.connect()