summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/ipv6/genericopt_posix.go
blob: 0a8d9883d2df4e180ab64c18295759eb2eaf39d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows

package ipv6

import (
	"syscall"

	"golang.org/x/net/internal/netreflect"
)

// TrafficClass returns the traffic class field value for outgoing
// packets.
func (c *genericOpt) TrafficClass() (int, error) {
	if !c.ok() {
		return 0, syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return 0, err
	}
	return getInt(s, &sockOpts[ssoTrafficClass])
}

// SetTrafficClass sets the traffic class field value for future
// outgoing packets.
func (c *genericOpt) SetTrafficClass(tclass int) error {
	if !c.ok() {
		return syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return err
	}
	return setInt(s, &sockOpts[ssoTrafficClass], tclass)
}

// HopLimit returns the hop limit field value for outgoing packets.
func (c *genericOpt) HopLimit() (int, error) {
	if !c.ok() {
		return 0, syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return 0, err
	}
	return getInt(s, &sockOpts[ssoHopLimit])
}

// SetHopLimit sets the hop limit field value for future outgoing
// packets.
func (c *genericOpt) SetHopLimit(hoplim int) error {
	if !c.ok() {
		return syscall.EINVAL
	}
	s, err := netreflect.SocketOf(c.Conn)
	if err != nil {
		return err
	}
	return setInt(s, &sockOpts[ssoHopLimit], hoplim)
}