1 // Copyright 2013 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.
12 "golang.org/x/net/internal/iana"
13 "golang.org/x/net/internal/nettest"
14 "golang.org/x/net/ipv6"
17 func TestConnUnicastSocketOptions(t *testing.T) {
19 case "nacl", "plan9", "windows":
20 t.Skipf("not supported on %s", runtime.GOOS)
23 t.Skip("ipv6 is not supported")
26 ln, err := net.Listen("tcp6", "[::1]:0")
32 errc := make(chan error, 1)
42 c, err := net.Dial("tcp6", ln.Addr().String())
48 testUnicastSocketOptions(t, ipv6.NewConn(c))
50 if err := <-errc; err != nil {
51 t.Errorf("server: %v", err)
55 var packetConnUnicastSocketOptionTests = []struct {
56 net, proto, addr string
58 {"udp6", "", "[::1]:0"},
59 {"ip6", ":ipv6-icmp", "::1"},
62 func TestPacketConnUnicastSocketOptions(t *testing.T) {
64 case "nacl", "plan9", "windows":
65 t.Skipf("not supported on %s", runtime.GOOS)
68 t.Skip("ipv6 is not supported")
71 m, ok := nettest.SupportsRawIPSocket()
72 for _, tt := range packetConnUnicastSocketOptionTests {
73 if tt.net == "ip6" && !ok {
77 c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
83 testUnicastSocketOptions(t, ipv6.NewPacketConn(c))
87 type testIPv6UnicastConn interface {
88 TrafficClass() (int, error)
89 SetTrafficClass(int) error
90 HopLimit() (int, error)
91 SetHopLimit(int) error
94 func testUnicastSocketOptions(t *testing.T, c testIPv6UnicastConn) {
95 tclass := iana.DiffServCS0 | iana.NotECNTransport
96 if err := c.SetTrafficClass(tclass); err != nil {
98 case "darwin": // older darwin kernels don't support IPV6_TCLASS option
99 t.Logf("not supported on %s", runtime.GOOS)
104 if v, err := c.TrafficClass(); err != nil {
106 } else if v != tclass {
107 t.Fatalf("got %v; want %v", v, tclass)
112 if err := c.SetHopLimit(hoplim); err != nil {
115 if v, err := c.HopLimit(); err != nil {
117 } else if v != hoplim {
118 t.Fatalf("got %v; want %v", v, hoplim)