新TAP测试(TODO 解析arp)

This commit is contained in:
黄思敏 2022-09-01 11:40:59 +08:00
parent d1fd2dae03
commit b358c2ec56

View File

@ -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))
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: 判断地址 转入对应的客户端发送数据