This commit is contained in:
黄思敏 2022-08-29 09:37:00 +08:00
parent 26d8023cf1
commit fb1b65184e
2 changed files with 6 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"log" "log"
"net"
"os/exec" "os/exec"
gen "slimming/proto/gen" gen "slimming/proto/gen"
"strings" "strings"
@ -131,7 +132,7 @@ func (nc *NetCard) Run() {
func NewNetCard() *NetCard { func NewNetCard() *NetCard {
config := water.Config{ config := water.Config{
DeviceType: water.TAP, DeviceType: water.TUN,
PlatformSpecificParams: water.PlatformSpecificParams{ PlatformSpecificParams: water.PlatformSpecificParams{
Name: "stun", Name: "stun",
}, },
@ -179,7 +180,7 @@ func (nc *NetCard) runRead() {
log.Fatal(err) log.Fatal(err)
} }
rframe = rframe[:n] rframe = rframe[:n]
if !waterutil.IsIPv4(rframe) { if !waterutil.IsIPv4(rframe) || waterutil.IPv4Source(rframe).Equal(net.IPv4(0, 0, 0, 0)) {
continue continue
} }
@ -195,9 +196,8 @@ func (nc *NetCard) runRead() {
// log.Printf("Payload: % x\n", rframe.Payload()) // log.Printf("Payload: % x\n", rframe.Payload())
log.Printf("Dst: %s Src %s\n", waterutil.IPv4Destination(rframe), waterutil.IPv4Source(rframe))
log.Printf("Ethertype: % x %v\n", rframe.Ethertype(), waterutil.IsIPv4(rframe)) log.Printf("Ethertype: % x %v\n", rframe.Ethertype(), waterutil.IsIPv4(rframe))
log.Printf("Dst: %s Src %s\n", waterutil.IPv4Destination(rframe), waterutil.IPv4Source(rframe))
var buffer *ExchangeBuffer var buffer *ExchangeBuffer
if buffer, ok = bytesMap[realAddr]; !ok { if buffer, ok = bytesMap[realAddr]; !ok {

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 (