proxy: improve addr handling

This commit is contained in:
nadoo committed 2022-01-28 23:35:29 +08:00
1 parent e12642b47a
commit 7e7c7553cc
12 files changed
+99 -109

No files matched your search

+4 -6
View File
@@ -4,6 +4,7 @@ import (
"encoding/binary"
"io"
"net"
"net/netip"
"strconv"
"github.com/nadoo/glider/pkg/pool"
@@ -39,16 +40,13 @@ func ParseAddr(s string) (Atyp, Addr, Port, error) {
return 0, nil, 0, err
}
if ip := net.ParseIP(host); ip != nil {
if ip4 := ip.To4(); ip4 != nil {
addr = make([]byte, net.IPv4len)
if ip, err := netip.ParseAddr(host); err == nil {
if ip.Is4() {
atyp = AtypIP4
copy(addr[:], ip4)
} else {
addr = make([]byte, net.IPv6len)
atyp = AtypIP6
copy(addr[:], ip)
}
addr = ip.AsSlice()
} else {
if len(host) > MaxHostLen {
return 0, nil, 0, err