This commit is contained in:
黄思敏 2022-08-29 15:14:44 +08:00
parent 597cbf739b
commit 3e32746ed5
2 changed files with 25 additions and 24 deletions

21
main.go
View File

@ -26,13 +26,7 @@ var (
flagAddr = flag.String("addr", "", "addr set") flagAddr = flag.String("addr", "", "addr set")
) )
func testmain() { func startCard() {
flag.Parse()
var a chan bool = make(chan bool)
go func() {
<-a
cmdstr := fmt.Sprintf("ip addr add %s dev stun", *flagAddr) cmdstr := fmt.Sprintf("ip addr add %s dev stun", *flagAddr)
log.Println(cmdstr) log.Println(cmdstr)
cmd := strings.Split(cmdstr, " ") cmd := strings.Split(cmdstr, " ")
@ -47,10 +41,13 @@ func testmain() {
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }
}() }
func testmain() {
flag.Parse()
config := water.Config{ config := water.Config{
DeviceType: water.TUN, DeviceType: water.TAP,
} }
config.Name = "stun" config.Name = "stun"
@ -58,10 +55,12 @@ func testmain() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
a <- true
var frame ethernet.Frame
startCard()
var frame ethernet.Frame
for { for {
frame.Resize(1500) frame.Resize(1500)
n, err := ifce.Read([]byte(frame)) n, err := ifce.Read([]byte(frame))
if err != nil { if err != nil {

View File

@ -147,6 +147,7 @@ func NewNetCard() *NetCard {
PlatformSpecificParams: water.PlatformSpecificParams{ PlatformSpecificParams: water.PlatformSpecificParams{
Name: "stun", Name: "stun",
Persist: true, Persist: true,
MultiQueue: true,
}, },
} }
@ -219,6 +220,7 @@ func (nc *NetCard) runRead() {
bytesMap[realAddr] = buffer bytesMap[realAddr] = buffer
} }
ifce.Write([]byte(rframe))
buffer.BytesArray = append(buffer.BytesArray, []byte(rframe)) buffer.BytesArray = append(buffer.BytesArray, []byte(rframe))
} }