From b358c2ec56d646c0a804c05ef4fedc9094d86483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Thu, 1 Sep 2022 11:40:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0TAP=E6=B5=8B=E8=AF=95(TODO=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90arp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- netcard.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/netcard.go b/netcard.go index bff036e..be0bfd5 100644 --- a/netcard.go +++ b/netcard.go @@ -16,7 +16,6 @@ import ( "github.com/474420502/perfectshutdown" "github.com/songgao/packets/ethernet" "github.com/songgao/water" - "github.com/songgao/water/waterutil" "google.golang.org/grpc" ) @@ -93,7 +92,6 @@ func NewNetTunnel() *NetTunnel { SwapBytes(frame, 0, frame, 6, 6) binary.BigEndian.PutUint16(frame[20:22], 2) SwapBytes(frame, 22, frame, 32, 10) - nt.ifce.Write(frame) //TODO: 解析arp 回应arp @@ -110,13 +108,18 @@ func NewNetTunnel() *NetTunnel { // }) case ethernet.IPv4: payload := frame.Payload() - log.Printf("bytes len: %d type(ipv4): % x", len(rbuf), frame.Ethertype()) + // dst := net.IP(payload[16:20]).To4() + log.Printf("bytes len: %d type(ipv4): % x", len(rbuf), frame.Ethertype()) log.Println(frame.Source(), net.IP(payload[12:16]).To4(), binary.BigEndian.Uint16(payload[20:22]), frame.Destination(), net.IP(payload[16:20]).To4(), binary.BigEndian.Uint16(payload[22:24])) - log.Printf("src: %s(%d) dst: %s(%d)", waterutil.IPv4Source(frame), waterutil.IPv4SourcePort(frame), waterutil.IPv4Destination(frame), waterutil.IPv4DestinationPort(frame)) - log.Println(len(frame)) - + ipv4key := binary.BigEndian.Uint32(payload[16:20]) + if v, ok := nt.clients.Load(ipv4key); ok { + client := v.(*RPCClient) + client.CheckConnect() + client.Frame <- frame + log.Println(len(frame)) + } } // TODO: 判断地址 转入对应的客户端发送数据