Przeglądaj źródła

Merge pull request #223 from boypt/fixdohv6

fix ipv6 doh-ip
tags/v2.1.3^2
Sergey Arkhipov 4 lat temu
rodzic
commit
853395106b
No account linked to committer's email address
1 zmienionych plików z 11 dodań i 2 usunięć
  1. 11
    2
      network/dns_resolver.go

+ 11
- 2
network/dns_resolver.go Wyświetl plik

1
 package network
1
 package network
2
 
2
 
3
 import (
3
 import (
4
+	"fmt"
5
+	"net"
4
 	"net/http"
6
 	"net/http"
5
 	"sync"
7
 	"sync"
6
 	"time"
8
 	"time"
83
 	return ips
85
 	return ips
84
 }
86
 }
85
 
87
 
86
-func newDNSResolver(hostname string, httpClient *http.Client) *dnsResolver {
87
-	return &dnsResolver{
88
+func newDNSResolver(hostname string, httpClient *http.Client) (ret *dnsResolver) {
89
+	if net.ParseIP(hostname).To4() == nil {
90
+		// the hostname is an IPv6 address
91
+		hostname = fmt.Sprintf("[%s]", hostname)
92
+	}
93
+
94
+	ret = &dnsResolver{
88
 		resolver: doh.Resolver{
95
 		resolver: doh.Resolver{
89
 			Host:       hostname,
96
 			Host:       hostname,
90
 			Class:      doh.IN,
97
 			Class:      doh.IN,
92
 		},
99
 		},
93
 		cache: map[string]dnsResolverCacheEntry{},
100
 		cache: map[string]dnsResolverCacheEntry{},
94
 	}
101
 	}
102
+
103
+	return
95
 }
104
 }

Ładowanie…
Anuluj
Zapisz