refactor: rename cmd dev to run (#684)

* refactor: code

* refactor: optimize code
This commit is contained in:
naison
2025-08-04 23:00:38 +08:00
committed by GitHub
parent 2d5653ee2b
commit b3b13fce86
21 changed files with 110 additions and 104 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/pkg/errors"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
@@ -39,8 +40,15 @@ func UDPForwarder(ctx context.Context, s *stack.Stack) func(id stack.TransportEn
return
}
var network string
if id.LocalAddress.To4() != (tcpip.Address{}) {
network = "udp4"
} else {
network = "udp6"
}
// dial dst
remote, err1 := net.DialUDP("udp", nil, dst)
remote, err1 := net.DialUDP(network, nil, dst)
if err1 != nil {
plog.G(ctx).Errorf("[TUN-UDP] Failed to connect dst: %s: %v", dst.String(), err1)
return