新TAP测试(TODO 解析arp)

This commit is contained in:
黄思敏 2022-09-01 11:59:28 +08:00
parent b9dedde845
commit 5fadad660c

View File

@ -20,7 +20,9 @@ import (
)
type NetTunnel struct {
ifce *water.Interface
ifce *water.Interface
ifmac []byte
shutdown *perfectshutdown.PerfectShutdown
writer chan []byte
reader chan []byte
@ -78,6 +80,17 @@ func NewNetTunnel() *NetTunnel {
log.Panic(err)
}
ifas, err := net.Interfaces()
if err != nil {
log.Panic(err)
}
for _, ifa := range ifas {
if ifa.Name == nt.ifce.Name() {
nt.ifmac = ifa.HardwareAddr[0:6]
}
}
go func() {
for rbuf := range nt.reader {
@ -134,6 +147,7 @@ func NewNetTunnel() *NetTunnel {
for wbuf := range nt.writer {
var frame ethernet.Frame = wbuf
log.Printf("ifce write %d", len(frame))
copy(frame[0:6], nt.ifmac)
_, err := nt.ifce.Write(frame)
if err != nil {
log.Println(err)