Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
756df8e0
Commit
756df8e0
authored
May 02, 2011
by
Mikio Hara
Committed by
Russ Cox
May 02, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: fix ipv6 test
Fixes #1767. R=rsc CC=golang-dev
https://golang.org/cl/4436073
parent
540feaae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
27 deletions
+69
-27
src/pkg/net/dialgoogle_test.go
src/pkg/net/dialgoogle_test.go
+69
-27
No files found.
src/pkg/net/dialgoogle_test.go
View file @
756df8e0
...
...
@@ -41,20 +41,6 @@ func doDial(t *testing.T, network, addr string) {
fd
.
Close
()
}
var
googleaddrs
=
[]
string
{
"%d.%d.%d.%d:80"
,
"www.google.com:80"
,
"%d.%d.%d.%d:http"
,
"www.google.com:http"
,
"%03d.%03d.%03d.%03d:0080"
,
"[::ffff:%d.%d.%d.%d]:80"
,
"[::ffff:%02x%02x:%02x%02x]:80"
,
"[0:0:0:0:0000:ffff:%d.%d.%d.%d]:80"
,
"[0:0:0:0:000000:ffff:%d.%d.%d.%d]:80"
,
"[0:0:0:0:0:ffff::%d.%d.%d.%d]:80"
,
"[2001:4860:0:2001::68]:80"
,
// ipv6.google.com; removed if ipv6 flag not set
}
func
TestLookupCNAME
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
// Don't use external network.
...
...
@@ -67,16 +53,25 @@ func TestLookupCNAME(t *testing.T) {
}
}
func
TestDialGoogle
(
t
*
testing
.
T
)
{
var
googleaddrsipv4
=
[]
string
{
"%d.%d.%d.%d:80"
,
"www.google.com:80"
,
"%d.%d.%d.%d:http"
,
"www.google.com:http"
,
"%03d.%03d.%03d.%03d:0080"
,
"[::ffff:%d.%d.%d.%d]:80"
,
"[::ffff:%02x%02x:%02x%02x]:80"
,
"[0:0:0:0:0000:ffff:%d.%d.%d.%d]:80"
,
"[0:0:0:0:000000:ffff:%d.%d.%d.%d]:80"
,
"[0:0:0:0:0:ffff::%d.%d.%d.%d]:80"
,
}
func
TestDialGoogleIPv4
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
// Don't use external network.
t
.
Logf
(
"skipping external network test during -short"
)
return
}
// If no ipv6 tunnel, don't try the last address.
if
!*
ipv6
{
googleaddrs
[
len
(
googleaddrs
)
-
1
]
=
""
}
// Insert an actual IPv4 address for google.com
// into the table.
...
...
@@ -95,14 +90,14 @@ func TestDialGoogle(t *testing.T) {
t
.
Fatalf
(
"no IPv4 addresses for www.google.com"
)
}
for
i
,
s
:=
range
googleaddrs
{
for
i
,
s
:=
range
googleaddrs
ipv4
{
if
strings
.
Contains
(
s
,
"%"
)
{
googleaddrs
[
i
]
=
fmt
.
Sprintf
(
s
,
ip
[
0
],
ip
[
1
],
ip
[
2
],
ip
[
3
])
googleaddrs
ipv4
[
i
]
=
fmt
.
Sprintf
(
s
,
ip
[
0
],
ip
[
1
],
ip
[
2
],
ip
[
3
])
}
}
for
i
:=
0
;
i
<
len
(
googleaddrs
);
i
++
{
addr
:=
googleaddrs
[
i
]
for
i
:=
0
;
i
<
len
(
googleaddrs
ipv4
);
i
++
{
addr
:=
googleaddrs
ipv4
[
i
]
if
addr
==
""
{
continue
}
...
...
@@ -110,20 +105,67 @@ func TestDialGoogle(t *testing.T) {
doDial
(
t
,
"tcp"
,
addr
)
if
addr
[
0
]
!=
'['
{
doDial
(
t
,
"tcp4"
,
addr
)
if
!
preferIPv4
{
// make sure preferIPv4 flag works.
preferIPv4
=
true
syscall
.
SocketDisableIPv6
=
true
doDial
(
t
,
"tcp"
,
addr
)
doDial
(
t
,
"tcp4"
,
addr
)
syscall
.
SocketDisableIPv6
=
false
preferIPv4
=
false
}
}
}
}
var
googleaddrsipv6
=
[]
string
{
"[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:80"
,
"ipv6.google.com:80"
,
"[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:http"
,
"ipv6.google.com:http"
,
}
func
TestDialGoogleIPv6
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
// Don't use external network.
t
.
Logf
(
"skipping external network test during -short"
)
return
}
// Only run tcp6 if the kernel will take it.
if
!*
ipv6
||
!
kernelSupportsIPv6
()
{
return
}
// Insert an actual IPv6 address for ipv6.google.com
// into the table.
addrs
,
err
:=
LookupIP
(
"ipv6.google.com"
)
if
err
!=
nil
{
t
.
Fatalf
(
"lookup ipv6.google.com: %v"
,
err
)
}
var
ip
IP
for
_
,
addr
:=
range
addrs
{
if
x
:=
addr
.
To16
();
x
!=
nil
{
ip
=
x
break
}
}
if
ip
==
nil
{
t
.
Fatalf
(
"no IPv6 addresses for ipv6.google.com"
)
}
for
i
,
s
:=
range
googleaddrsipv6
{
if
strings
.
Contains
(
s
,
"%"
)
{
googleaddrsipv6
[
i
]
=
fmt
.
Sprintf
(
s
,
ip
[
0
],
ip
[
1
],
ip
[
2
],
ip
[
3
],
ip
[
4
],
ip
[
5
],
ip
[
6
],
ip
[
7
],
ip
[
8
],
ip
[
9
],
ip
[
10
],
ip
[
11
],
ip
[
12
],
ip
[
13
],
ip
[
14
],
ip
[
15
])
}
}
// Only run tcp6 if the kernel will take it.
if
kernelSupportsIPv6
()
{
doDial
(
t
,
"tcp6"
,
addr
)
for
i
:=
0
;
i
<
len
(
googleaddrsipv6
);
i
++
{
addr
:=
googleaddrsipv6
[
i
]
if
addr
==
""
{
continue
}
t
.
Logf
(
"-- %s --"
,
addr
)
doDial
(
t
,
"tcp"
,
addr
)
doDial
(
t
,
"tcp6"
,
addr
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment