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

16
main.go
View File

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

View File

@ -272,8 +272,11 @@ func (nc *NetCard) runWrite() {
for _, buf := range bufs { for _, buf := range bufs {
log.Printf("get wframes decode len: %d", len(buf)) 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)) 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 { if err != nil {
log.Panic(err) log.Panic(err)
} }