新TAP测试(TODO 解析arp)

This commit is contained in:
黄思敏 2022-09-01 15:12:53 +08:00
parent 5ef9e2c42d
commit 137a7b14b2
2 changed files with 8 additions and 10 deletions

View File

@ -126,8 +126,8 @@ func NewNetTunnel() *NetTunnel {
payload := frame.Payload() payload := frame.Payload()
// dst := net.IP(payload[16:20]).To4() // dst := net.IP(payload[16:20]).To4()
log.Printf("bytes len: %d type(ipv4): % x", len(rbuf), frame.Ethertype()) // 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.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]))
ipv4key := binary.BigEndian.Uint32(payload[16:20]) ipv4key := binary.BigEndian.Uint32(payload[16:20])
if v, ok := nt.clients.Load(ipv4key); ok { if v, ok := nt.clients.Load(ipv4key); ok {
@ -149,10 +149,12 @@ func NewNetTunnel() *NetTunnel {
go func() { go func() {
for wbuf := range nt.writer { for wbuf := range nt.writer {
var frame ethernet.Frame = wbuf var frame ethernet.Frame = wbuf
copy(frame[0:6], nt.ifmac) // copy(frame[0:6], nt.ifmac)
log.Printf("ifce write %d ", len(frame))
payload := frame.Payload() // payload := frame.Payload()
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("ifce write %d ", len(frame))
// 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]))
_, err := nt.ifce.Write(frame) _, err := nt.ifce.Write(frame)
if err != nil { if err != nil {

View File

@ -9,7 +9,6 @@ import (
"net" "net"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
"github.com/songgao/water/waterutil"
) )
func Compress(writer io.Writer, data [][]byte) { func Compress(writer io.Writer, data [][]byte) {
@ -17,7 +16,6 @@ func Compress(writer io.Writer, data [][]byte) {
// encode gob // encode gob
enc := gob.NewEncoder(writer) enc := gob.NewEncoder(writer)
log.Printf("send to target %s source bytes: %d", waterutil.IPv4Destination(data[0]), len(data[0]))
err := enc.Encode(data) err := enc.Encode(data)
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
@ -38,8 +36,6 @@ func Compress(writer io.Writer, data [][]byte) {
func Decompress(data []byte) (frames [][]byte) { func Decompress(data []byte) (frames [][]byte) {
var err error var err error
log.Printf("get data bytes len: %d", len(data))
var buf = bytes.NewBuffer(data) var buf = bytes.NewBuffer(data)
var zdec *zstd.Decoder var zdec *zstd.Decoder
zdec, err = zstd.NewReader(buf) zdec, err = zstd.NewReader(buf)