This commit is contained in:
黄思敏 2022-08-29 18:01:29 +08:00
parent bca066e547
commit 806173ff92
2 changed files with 14 additions and 7 deletions

14
main.go
View File

@ -18,8 +18,8 @@ func init() {
//go:generate bash -c "protoc --go_out=plugins=grpc:. proto/*.proto"
func main() {
// testmain()
NewNetCard().Run()
testmain()
// NewNetCard().Run()
}
var (
@ -47,7 +47,7 @@ func testmain() {
flag.Parse()
config := water.Config{
DeviceType: water.TAP,
DeviceType: water.TUN,
}
config.Name = "stun"
@ -68,9 +68,13 @@ func testmain() {
}
frame = frame[:n]
log.Printf("DstMac: %s SrcMac: %s\n", waterutil.MACDestination(frame), waterutil.MACSource(frame))
log.Printf("DstIP: %s SrcIP: %s\n", waterutil.IPv4Destination(frame), waterutil.IPv4Source(frame))
if frame.Ethertype() != ethernet.ARP {
log.Printf("Ethertype: % x\n", frame.Ethertype())
log.Printf("DstMac: %s SrcMac: %s\n", waterutil.IPv4Destination(frame), waterutil.IPv4Source(frame))
log.Printf("DstPort: %d SrcPort: %d\n", waterutil.IPv4DestinationPort(frame), waterutil.IPv4SourcePort(frame))
}
// log.Printf("Payload: % x\n", frame.Payload())
ifce.Write(frame)

View File

@ -272,8 +272,11 @@ func (nc *NetCard) runWrite() {
for _, buf := range bufs {
log.Printf("get wframes decode len: %d", len(buf))
var wbuf []byte
wbuf = append(wbuf, buf[0:20]...)
wbuf = append(wbuf, waterutil.IPv4Payload(buf)...)
log.Printf("get decode frames decode source: %s dst: %s", waterutil.IPv4Source(buf), waterutil.IPv4Destination(buf))
_, err := ifce.Write(buf)
_, err := ifce.Write(wbuf)
if err != nil {
log.Panic(err)
}