新TAP测试(TODO 解析arp)
This commit is contained in:
parent
9f4c58e14a
commit
87a90722bd
30
netcard.go
30
netcard.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
@ -87,18 +88,25 @@ func NewNetTunnel() *NetTunnel {
|
|||
switch frame.Ethertype() {
|
||||
case ethernet.ARP:
|
||||
log.Printf("bytes len: %d type(arp): % x", len(rbuf), frame.Ethertype()) // 数据长度
|
||||
//TODO: 解析arp 回应arp
|
||||
nt.clients.Range(func(key, value any) bool {
|
||||
if key == nt.ipv4key {
|
||||
return true
|
||||
}
|
||||
|
||||
client := value.(*RPCClient)
|
||||
client.CheckConnect()
|
||||
client.Frame <- frame
|
||||
log.Println(client.realAddr)
|
||||
return true
|
||||
})
|
||||
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
|
||||
// nt.clients.Range(func(key, value any) bool {
|
||||
// if key == nt.ipv4key {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// client := value.(*RPCClient)
|
||||
// client.CheckConnect()
|
||||
// client.Frame <- frame
|
||||
// log.Println(client.realAddr)
|
||||
// return true
|
||||
// })
|
||||
case ethernet.IPv4:
|
||||
log.Printf("bytes len: %d type(ipv4): % x", len(rbuf), frame.Ethertype())
|
||||
log.Println(len(frame))
|
||||
|
|
7
utils.go
7
utils.go
|
@ -54,3 +54,10 @@ func Decompress(data []byte) (frames [][]byte) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func SwapBytes(frame1 []byte, start1 int, frame2 []byte, start2 int, size int) {
|
||||
var temp []byte = make([]byte, size)
|
||||
copy(temp, frame1[start1:start1+size])
|
||||
copy(frame1[start1:start1+size], frame2[start2:start2+size])
|
||||
copy(frame2[start2:start2+size], temp)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user