1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 // If an IPv6 tunnel is running (see go/stubl), we can try dialing a real IPv6 address.
15 var ipv6
= flag
.Bool("ipv6", false, "assume ipv6 tunnel is present")
17 // fd is already connected to the destination, port 80.
18 // Run an HTTP request to fetch the appropriate page.
19 func fetchGoogle(t
*testing
.T
, fd Conn
, network
, addr
string) {
20 req
:= []byte("GET /intl/en/privacy/ HTTP/1.0\r\nHost: www.google.com\r\n\r\n")
21 n
, err
:= fd
.Write(req
)
23 buf
:= make([]byte, 1000)
24 n
, err
= io
.ReadFull(fd
, buf
)
27 t
.Errorf("fetchGoogle: short HTTP read from %s %s - %v", network
, addr
, err
)
32 func doDial(t
*testing
.T
, network
, addr
string) {
33 fd
, err
:= Dial(network
, "", addr
)
35 t
.Errorf("Dial(%q, %q, %q) = _, %v", network
, "", addr
, err
)
38 fetchGoogle(t
, fd
, network
, addr
)
42 var googleaddrs
= []string{
46 "www.google.com:http",
47 "074.125.019.099:0080",
48 "[::ffff:74.125.19.99]:80",
49 "[::ffff:4a7d:1363]:80",
50 "[0:0:0:0:0000:ffff:74.125.19.99]:80",
51 "[0:0:0:0:000000:ffff:74.125.19.99]:80",
52 "[0:0:0:0:0:ffff::74.125.19.99]:80",
53 "[2001:4860:0:2001::68]:80", // ipv6.google.com; removed if ipv6 flag not set
56 func TestDialGoogle(t
*testing
.T
) {
57 // If no ipv6 tunnel, don't try the last address.
59 googleaddrs
[len(googleaddrs
)-1] = ""
62 for i
:= 0; i
< len(googleaddrs
); i
++ {
63 addr
:= googleaddrs
[i
]
67 t
.Logf("-- %s --", addr
)
68 doDial(t
, "tcp", addr
)
70 doDial(t
, "tcp4", addr
)
73 // make sure preferIPv4 flag works.
75 syscall
.SocketDisableIPv6
= true
76 doDial(t
, "tcp4", addr
)
77 syscall
.SocketDisableIPv6
= false
82 // Only run tcp6 if the kernel will take it.
83 if kernelSupportsIPv6() {
84 doDial(t
, "tcp6", addr
)