mirror of
https://github.com/golang/go
synced 2024-11-23 20:40:07 -07:00
net: make IPv6 capability test more suitable for address family selection on the dual IP stack node
For now we strictly use IPV6_V6ONLY=1 for IPv6-only communications and IPV6_V6ONLY=0 for both IPv4 and IPv6 communications. So let the capability test do the same. LGTM=iant R=golang-codereviews, gobot, iant CC=golang-codereviews https://golang.org/cl/80140044
This commit is contained in:
parent
753bdc0f47
commit
a05ffd85aa
@ -40,12 +40,13 @@ func probeIPv4Stack() bool {
|
|||||||
func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
|
func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
|
||||||
var probes = []struct {
|
var probes = []struct {
|
||||||
laddr TCPAddr
|
laddr TCPAddr
|
||||||
|
value int
|
||||||
ok bool
|
ok bool
|
||||||
}{
|
}{
|
||||||
// IPv6 communication capability
|
// IPv6 communication capability
|
||||||
{TCPAddr{IP: ParseIP("::1")}, false},
|
{laddr: TCPAddr{IP: ParseIP("::1")}, value: 1},
|
||||||
// IPv6 IPv4-mapped address communication capability
|
// IPv6 IPv4-mapped address communication capability
|
||||||
{TCPAddr{IP: IPv4(127, 0, 0, 1)}, false},
|
{laddr: TCPAddr{IP: IPv4(127, 0, 0, 1)}, value: 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range probes {
|
for i := range probes {
|
||||||
@ -54,7 +55,7 @@ func probeIPv6Stack() (supportsIPv6, supportsIPv4map bool) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer closesocket(s)
|
defer closesocket(s)
|
||||||
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
|
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, probes[i].value)
|
||||||
sa, err := probes[i].laddr.sockaddr(syscall.AF_INET6)
|
sa, err := probes[i].laddr.sockaddr(syscall.AF_INET6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user