chore: small optimizations

This commit is contained in:
nadoo committed 2022-01-28 15:12:02 +08:00
1 parent a814f8c545
commit e12642b47a
5 files changed
+32 -43

No files matched your search

+4 -5
View File
@@ -4,6 +4,7 @@ import (
"errors"
"io"
"net"
"net/netip"
"strconv"
"github.com/nadoo/glider/pkg/log"
@@ -74,15 +75,13 @@ func (s *Socks5) DialUDP(network, addr string) (pc net.PacketConn, writeTo net.A
buf := pool.GetBuffer(socks.MaxAddrLen)
defer pool.PutBuffer(buf)
var uAddress string
h, p, _ := net.SplitHostPort(uAddr.String())
uAddress := uAddr.String()
h, p, _ := net.SplitHostPort(uAddress)
// if returned bind ip is unspecified
if ip := net.ParseIP(h); ip != nil && ip.IsUnspecified() {
if ip, err := netip.ParseAddr(h); err == nil && ip.IsUnspecified() {
// indicate using conventional addr
h, _, _ = net.SplitHostPort(s.addr)
uAddress = net.JoinHostPort(h, p)
} else {
uAddress = uAddr.String()
}
pc, nextHop, err := s.dialer.DialUDP(network, uAddress)