Fix the issue of ipv6 prefer after lookupAddr
This commit is contained in:
1 parent
94e0644bc1
commit
681b559f85
1 file changed
+19
-10
+19
-10
@@ -135,18 +135,27 @@ func (d *ProtectedDialer) lookupAddr(addr string) (*resolved, error) {
|
||||
return nil, fmt.Errorf("domain %s Failed to resolve", addr)
|
||||
}
|
||||
|
||||
IPs := make([]net.IP, len(addrs))
|
||||
for i, ia := range addrs {
|
||||
IPs[i] = ia.IP
|
||||
IPs := make([]net.IP, 0)
|
||||
//ipv6 is prefer, append ipv6 then ipv4
|
||||
//ipv6 is not prefer, append ipv4 then ipv6
|
||||
if(d.preferIPv6) {
|
||||
for _, ia := range addrs {
|
||||
if(ia.IP.To4() == nil) {
|
||||
IPs = append(IPs, ia.IP)
|
||||
}
|
||||
}
|
||||
}
|
||||
// LookupIPAddr returns a slice of IPs with IPv6 addrs in front,
|
||||
// if user perfer not IPv6, revert the result so that IPv4 addr comes first
|
||||
if !d.preferIPv6 && len(IPs) > 1 && IPs[0].To4() == nil && IPs[len(IPs)-1].To4() != nil {
|
||||
for i := len(IPs)/2 - 1; i >= 0; i-- {
|
||||
opp := len(IPs) - 1 - i
|
||||
IPs[i], IPs[opp] = IPs[opp], IPs[i]
|
||||
for _, ia := range addrs {
|
||||
if(ia.IP.To4() != nil) {
|
||||
IPs = append(IPs, ia.IP)
|
||||
}
|
||||
log.Printf("PrepareDomain Prefer NOT IPv6 %v\n", IPs)
|
||||
}
|
||||
if(!d.preferIPv6) {
|
||||
for _, ia := range addrs {
|
||||
if(ia.IP.To4() == nil) {
|
||||
IPs = append(IPs, ia.IP)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rs := &resolved{
|
||||
|
||||
Reference in new issue
Block a user