mirror of
https://github.com/golang/go.git
synced 2025-11-10 05:31:03 +00:00
net: LookupHost and Resolve{TCP,UDP,IP}Addr should use zone from getaddrinfo
The unix and windows getaddrinfo calls return a zone with IPv6 addresses. IPv6 link-local addresses returned are only valid on the given zone. When the zone is dropped, connections to the address will fail. This patch replaces IP with IPAddr in several internal resolver functions, and plumbs through the zone. Change-Id: Ifea891654f586f15b76988464f82e04a42ccff6d Reviewed-on: https://go-review.googlesource.com/5851 Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
This commit is contained in:
parent
cbc854a799
commit
f00362b9ec
10 changed files with 132 additions and 119 deletions
|
|
@ -361,13 +361,15 @@ func goLookupHost(name string) (addrs []string, err error) {
|
|||
// Normally we let cgo use the C library resolver instead of
|
||||
// depending on our lookup code, so that Go and C get the same
|
||||
// answers.
|
||||
func goLookupIP(name string) (addrs []IP, err error) {
|
||||
func goLookupIP(name string) (addrs []IPAddr, err error) {
|
||||
// Use entries from /etc/hosts if possible.
|
||||
haddrs := lookupStaticHost(name)
|
||||
if len(haddrs) > 0 {
|
||||
for _, haddr := range haddrs {
|
||||
haddr, zone := splitHostZone(haddr)
|
||||
if ip := ParseIP(haddr); ip != nil {
|
||||
addrs = append(addrs, ip)
|
||||
addr := IPAddr{IP: ip, Zone: zone}
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
}
|
||||
if len(addrs) > 0 {
|
||||
|
|
@ -396,9 +398,15 @@ func goLookupIP(name string) (addrs []IP, err error) {
|
|||
}
|
||||
switch racer.qtype {
|
||||
case dnsTypeA:
|
||||
addrs = append(addrs, convertRR_A(racer.rrs)...)
|
||||
for _, ip := range convertRR_A(racer.rrs) {
|
||||
addr := IPAddr{IP: ip}
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
case dnsTypeAAAA:
|
||||
addrs = append(addrs, convertRR_AAAA(racer.rrs)...)
|
||||
for _, ip := range convertRR_AAAA(racer.rrs) {
|
||||
addr := IPAddr{IP: ip}
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(addrs) == 0 && lastErr != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue