chore: rewrite verifyIP6

This commit is contained in:
wwqgtxx 2023-04-19 19:25:21 +08:00
parent 47df97322d
commit 4ef99294e7

View file

@ -3,6 +3,7 @@ package config
import (
"fmt"
"net"
"net/netip"
"strings"
"github.com/Dreamacro/clash/adapter/outboundgroup"
@ -149,20 +150,11 @@ func proxyGroupsDagSort(groupsConfig []map[string]any) error {
}
func verifyIP6() bool {
addrs, err := net.InterfaceAddrs()
if err != nil {
return false
}
for _, addr := range addrs {
ipNet, isIpNet := addr.(*net.IPNet)
if isIpNet && !ipNet.IP.IsLoopback() {
if ipNet.IP.To16() != nil {
s := ipNet.IP.String()
for i := 0; i < len(s); i++ {
switch s[i] {
case ':':
return true
}
if iAddrs, err := net.InterfaceAddrs(); err == nil {
for _, addr := range iAddrs {
if prefix, err := netip.ParsePrefix(addr.String()); err == nil {
if addr := prefix.Addr().Unmap(); addr.Is6() && addr.IsGlobalUnicast() {
return true
}
}
}