From 5fadad660c3eaa40c8dc86b7a04b3f1b1cea263e 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:59:28 +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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/netcard.go b/netcard.go index 918cfcf..f9949ae 100644 --- a/netcard.go +++ b/netcard.go @@ -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)