Refactor: metadata use netip.Addr
This commit is contained in:
14
dns/util.go
14
dns/util.go
@ -5,9 +5,11 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/Dreamacro/clash/common/cache"
|
||||
"github.com/Dreamacro/clash/common/nnip"
|
||||
"github.com/Dreamacro/clash/component/dialer"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
@ -96,15 +98,15 @@ func handleMsgWithEmptyAnswer(r *D.Msg) *D.Msg {
|
||||
return msg
|
||||
}
|
||||
|
||||
func msgToIP(msg *D.Msg) []net.IP {
|
||||
ips := []net.IP{}
|
||||
func msgToIP(msg *D.Msg) []netip.Addr {
|
||||
ips := []netip.Addr{}
|
||||
|
||||
for _, answer := range msg.Answer {
|
||||
switch ans := answer.(type) {
|
||||
case *D.AAAA:
|
||||
ips = append(ips, ans.AAAA)
|
||||
ips = append(ips, nnip.IpToAddr(ans.AAAA))
|
||||
case *D.A:
|
||||
ips = append(ips, ans.A)
|
||||
ips = append(ips, nnip.IpToAddr(ans.A))
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +131,7 @@ func (wpc *wrapPacketConn) RemoteAddr() net.Addr {
|
||||
return wpc.rAddr
|
||||
}
|
||||
|
||||
func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP net.IP, port string, opts ...dialer.Option) (net.Conn, error) {
|
||||
func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP netip.Addr, port string, opts ...dialer.Option) (net.Conn, error) {
|
||||
adapter, ok := tunnel.Proxies()[adapterName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("proxy adapter [%s] not found", adapterName)
|
||||
@ -144,7 +146,7 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ
|
||||
}
|
||||
|
||||
addrType := C.AtypIPv4
|
||||
if dstIP.To4() == nil {
|
||||
if dstIP.Is6() {
|
||||
addrType = C.AtypIPv6
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user