ipv6: update example for the use of dual stack listener
Updates golang/go#13612.
Change-Id: Ic139b6f862a2a24d549bd1f502299a7eac2f0e38
Reviewed-on: https://go-review.googlesource.com/17799
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/ipv6/example_test.go b/ipv6/example_test.go
index a2a3030..e761aa2 100644
--- a/ipv6/example_test.go
+++ b/ipv6/example_test.go
@@ -16,7 +16,7 @@
)
func ExampleConn_markingTCP() {
- ln, err := net.Listen("tcp6", "[::]:1024")
+ ln, err := net.Listen("tcp", "[::]:1024")
if err != nil {
log.Fatal(err)
}
@@ -29,12 +29,14 @@
}
go func(c net.Conn) {
defer c.Close()
- p := ipv6.NewConn(c)
- if err := p.SetTrafficClass(0x28); err != nil { // DSCP AF11
- log.Fatal(err)
- }
- if err := p.SetHopLimit(128); err != nil {
- log.Fatal(err)
+ if c.RemoteAddr().(*net.TCPAddr).IP.To16() != nil && c.RemoteAddr().(*net.TCPAddr).IP.To4() == nil {
+ p := ipv6.NewConn(c)
+ if err := p.SetTrafficClass(0x28); err != nil { // DSCP AF11
+ log.Fatal(err)
+ }
+ if err := p.SetHopLimit(128); err != nil {
+ log.Fatal(err)
+ }
}
if _, err := c.Write([]byte("HELLO-R-U-THERE-ACK")); err != nil {
log.Fatal(err)