From 806173ff92e51b382f85b0676900a39741d550c6 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 18:01:29 +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 --- main.go | 16 ++++++++++------ netcard.go | 5 ++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index f302671..736ec7b 100644 --- a/main.go +++ b/main.go @@ -18,8 +18,8 @@ func init() { //go:generate bash -c "protoc --go_out=plugins=grpc:. proto/*.proto" func main() { - // testmain() - NewNetCard().Run() + testmain() + // NewNetCard().Run() } var ( @@ -47,7 +47,7 @@ func testmain() { flag.Parse() config := water.Config{ - DeviceType: water.TAP, + DeviceType: water.TUN, } config.Name = "stun" @@ -68,9 +68,13 @@ func testmain() { } frame = frame[:n] - log.Printf("DstMac: %s SrcMac: %s\n", waterutil.MACDestination(frame), waterutil.MACSource(frame)) - log.Printf("DstIP: %s SrcIP: %s\n", waterutil.IPv4Destination(frame), waterutil.IPv4Source(frame)) - log.Printf("Ethertype: % x\n", frame.Ethertype()) + if frame.Ethertype() != ethernet.ARP { + log.Printf("Ethertype: % x\n", frame.Ethertype()) + + log.Printf("DstMac: %s SrcMac: %s\n", waterutil.IPv4Destination(frame), waterutil.IPv4Source(frame)) + log.Printf("DstPort: %d SrcPort: %d\n", waterutil.IPv4DestinationPort(frame), waterutil.IPv4SourcePort(frame)) + } + // log.Printf("Payload: % x\n", frame.Payload()) ifce.Write(frame) diff --git a/netcard.go b/netcard.go index 9d2cdd3..709b6e9 100644 --- a/netcard.go +++ b/netcard.go @@ -272,8 +272,11 @@ func (nc *NetCard) runWrite() { for _, buf := range bufs { log.Printf("get wframes decode len: %d", len(buf)) + var wbuf []byte + wbuf = append(wbuf, buf[0:20]...) + wbuf = append(wbuf, waterutil.IPv4Payload(buf)...) log.Printf("get decode frames decode source: %s dst: %s", waterutil.IPv4Source(buf), waterutil.IPv4Destination(buf)) - _, err := ifce.Write(buf) + _, err := ifce.Write(wbuf) if err != nil { log.Panic(err) }