David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 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. |
| 4 | |
| 5 | package ipv6 |
| 6 | |
| 7 | import "syscall" |
| 8 | |
| 9 | // TrafficClass returns the traffic class field value for outgoing |
| 10 | // packets. |
| 11 | func (c *genericOpt) TrafficClass() (int, error) { |
| 12 | if !c.ok() { |
| 13 | return 0, syscall.EINVAL |
| 14 | } |
| 15 | so, ok := sockOpts[ssoTrafficClass] |
| 16 | if !ok { |
| 17 | return 0, errOpNoSupport |
| 18 | } |
| 19 | return so.GetInt(c.Conn) |
| 20 | } |
| 21 | |
| 22 | // SetTrafficClass sets the traffic class field value for future |
| 23 | // outgoing packets. |
| 24 | func (c *genericOpt) SetTrafficClass(tclass int) error { |
| 25 | if !c.ok() { |
| 26 | return syscall.EINVAL |
| 27 | } |
| 28 | so, ok := sockOpts[ssoTrafficClass] |
| 29 | if !ok { |
| 30 | return errOpNoSupport |
| 31 | } |
| 32 | return so.SetInt(c.Conn, tclass) |
| 33 | } |
| 34 | |
| 35 | // HopLimit returns the hop limit field value for outgoing packets. |
| 36 | func (c *genericOpt) HopLimit() (int, error) { |
| 37 | if !c.ok() { |
| 38 | return 0, syscall.EINVAL |
| 39 | } |
| 40 | so, ok := sockOpts[ssoHopLimit] |
| 41 | if !ok { |
| 42 | return 0, errOpNoSupport |
| 43 | } |
| 44 | return so.GetInt(c.Conn) |
| 45 | } |
| 46 | |
| 47 | // SetHopLimit sets the hop limit field value for future outgoing |
| 48 | // packets. |
| 49 | func (c *genericOpt) SetHopLimit(hoplim int) error { |
| 50 | if !c.ok() { |
| 51 | return syscall.EINVAL |
| 52 | } |
| 53 | so, ok := sockOpts[ssoHopLimit] |
| 54 | if !ok { |
| 55 | return errOpNoSupport |
| 56 | } |
| 57 | return so.SetInt(c.Conn, hoplim) |
| 58 | } |