Commit 50effb65 authored by Christopher Wedgwood's avatar Christopher Wedgwood Committed by Russ Cox

net: name-based destination address selection

getaddrinfo() orders the addresses according to RFC 3484.

This means when IPv6 is working on a host we get results like:
    []string = {"2001:4810::110", "66.117.47.214"}

and when it's not working we get:
    []string = {"66.117.47.214", "2001:4810::110"}

thus can drop firstFavoriteAddr.

This also means /etc/gai.conf works on relevant systems.

R=rsc, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/4557058
parent 91cc1e6b
...@@ -253,7 +253,7 @@ func hostToIP(net, host string) (ip IP, err os.Error) { ...@@ -253,7 +253,7 @@ func hostToIP(net, host string) (ip IP, err os.Error) {
err = err1 err = err1
goto Error goto Error
} }
addr = firstFavoriteAddr(filter, addrs) addr = firstSupportedAddr(filter, addrs)
if addr == nil { if addr == nil {
// should not happen // should not happen
err = &AddrError{"LookupHost returned no suitable address", addrs[0]} err = &AddrError{"LookupHost returned no suitable address", addrs[0]}
......
...@@ -98,23 +98,6 @@ func favoriteAddrFamily(net string, raddr, laddr sockaddr, mode string) int { ...@@ -98,23 +98,6 @@ func favoriteAddrFamily(net string, raddr, laddr sockaddr, mode string) int {
return syscall.AF_INET6 return syscall.AF_INET6
} }
func firstFavoriteAddr(filter func(IP) IP, addrs []string) (addr IP) {
if filter == anyaddr {
// We'll take any IP address, but since the dialing code
// does not yet try multiple addresses, prefer to use
// an IPv4 address if possible. This is especially relevant
// if localhost resolves to [ipv6-localhost, ipv4-localhost].
// Too much code assumes localhost == ipv4-localhost.
addr = firstSupportedAddr(ipv4only, addrs)
if addr == nil {
addr = firstSupportedAddr(anyaddr, addrs)
}
} else {
addr = firstSupportedAddr(filter, addrs)
}
return
}
func firstSupportedAddr(filter func(IP) IP, addrs []string) IP { func firstSupportedAddr(filter func(IP) IP, addrs []string) IP {
for _, s := range addrs { for _, s := range addrs {
if addr := filter(ParseIP(s)); addr != nil { if addr := filter(ParseIP(s)); addr != nil {
...@@ -293,7 +276,7 @@ func hostPortToIP(net, hostport string) (ip IP, iport int, err os.Error) { ...@@ -293,7 +276,7 @@ func hostPortToIP(net, hostport string) (ip IP, iport int, err os.Error) {
err = err1 err = err1
goto Error goto Error
} }
addr = firstFavoriteAddr(filter, addrs) addr = firstSupportedAddr(filter, addrs)
if addr == nil { if addr == nil {
// should not happen // should not happen
err = &AddrError{"LookupHost returned no suitable address", addrs[0]} err = &AddrError{"LookupHost returned no suitable address", addrs[0]}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment