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.
8
"code.google.com/p/go.net/ipv6"
15
func TestConnUnicastSocketOptions(t *testing.T) {
17
case "plan9", "windows":
18
t.Skipf("not supported on %q", runtime.GOOS)
21
t.Skip("ipv6 is not supported")
24
ln, err := net.Listen("tcp6", "[::1]:0")
26
t.Fatalf("net.Listen failed: %v", err)
30
done := make(chan bool)
31
go acceptor(t, ln, done)
33
c, err := net.Dial("tcp6", ln.Addr().String())
35
t.Fatalf("net.Dial failed: %v", err)
39
testUnicastSocketOptions(t, ipv6.NewConn(c))
44
var packetConnUnicastSocketOptionTests = []struct {
45
net, proto, addr string
47
{"udp6", "", "[::1]:0"},
48
{"ip6", ":ipv6-icmp", "::1"},
51
func TestPacketConnUnicastSocketOptions(t *testing.T) {
53
case "plan9", "windows":
54
t.Skipf("not supported on %q", runtime.GOOS)
57
t.Skip("ipv6 is not supported")
60
for _, tt := range packetConnUnicastSocketOptionTests {
61
if tt.net == "ip6" && os.Getuid() != 0 {
62
t.Skip("must be root")
64
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
66
t.Fatalf("net.ListenPacket(%q, %q) failed: %v", tt.net+tt.proto, tt.addr, err)
70
testUnicastSocketOptions(t, ipv6.NewPacketConn(c))
74
type testIPv6UnicastConn interface {
75
TrafficClass() (int, error)
76
SetTrafficClass(int) error
77
HopLimit() (int, error)
78
SetHopLimit(int) error
81
func testUnicastSocketOptions(t *testing.T, c testIPv6UnicastConn) {
82
tclass := DiffServCS0 | NotECNTransport
83
if err := c.SetTrafficClass(tclass); err != nil {
84
t.Fatalf("ipv6.Conn.SetTrafficClass failed: %v", err)
86
if v, err := c.TrafficClass(); err != nil {
87
t.Fatalf("ipv6.Conn.TrafficClass failed: %v", err)
88
} else if v != tclass {
89
t.Fatalf("got unexpected traffic class %v; expected %v", v, tclass)
93
if err := c.SetHopLimit(hoplim); err != nil {
94
t.Fatalf("ipv6.Conn.SetHopLimit failed: %v", err)
96
if v, err := c.HopLimit(); err != nil {
97
t.Fatalf("ipv6.Conn.HopLimit failed: %v", err)
98
} else if v != hoplim {
99
t.Fatalf("got unexpected hop limit %v; expected %v", v, hoplim)