This commit is contained in:
黄思敏 2022-08-29 10:45:38 +08:00
parent 9288626d4e
commit 03eb17436a

View File

@ -184,14 +184,11 @@ func (nc *NetCard) runRead() {
for atomic.LoadInt32(&isLoop) > 0 { for atomic.LoadInt32(&isLoop) > 0 {
var rframe ethernet.Frame var rframe ethernet.Frame
rframe.Resize(1500) rframe.Resize(1500)
nc.Lock(func() {
n, err := ifce.Read([]byte(rframe)) n, err := ifce.Read([]byte(rframe))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
rframe = rframe[:n] rframe = rframe[:n]
})
if !waterutil.IsIPv4(rframe) || waterutil.IPv4Source(rframe).Equal(net.IPv4(0, 0, 0, 0)) { if !waterutil.IsIPv4(rframe) || waterutil.IPv4Source(rframe).Equal(net.IPv4(0, 0, 0, 0)) {
continue continue
@ -204,6 +201,7 @@ func (nc *NetCard) runRead() {
} }
}) })
if realAddr == "" { if realAddr == "" {
log.Printf("%s is not exists", waterutil.IPv4Destination(rframe))
continue continue
} }
@ -272,14 +270,12 @@ func (nc *NetCard) runWrite() {
log.Printf("get wframes decode len: %d", len(bufs[0])) log.Printf("get wframes decode len: %d", len(bufs[0]))
nc.Lock(func() {
for _, buf := range bufs { for _, buf := range bufs {
_, err := ifce.Write(buf) _, err := ifce.Write(buf)
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }
} }
})
} }