2017-05-11 22:39:54 +08:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
package ipv6
|
|
|
|
|
2017-07-23 15:51:42 +08:00
|
|
|
import "syscall"
|
2017-05-11 22:39:54 +08:00
|
|
|
|
|
|
|
// TrafficClass returns the traffic class field value for outgoing
|
|
|
|
// packets.
|
|
|
|
func (c *genericOpt) TrafficClass() (int, error) {
|
|
|
|
if !c.ok() {
|
|
|
|
return 0, syscall.EINVAL
|
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
so, ok := sockOpts[ssoTrafficClass]
|
|
|
|
if !ok {
|
|
|
|
return 0, errOpNoSupport
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
return so.GetInt(c.Conn)
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTrafficClass sets the traffic class field value for future
|
|
|
|
// outgoing packets.
|
|
|
|
func (c *genericOpt) SetTrafficClass(tclass int) error {
|
|
|
|
if !c.ok() {
|
|
|
|
return syscall.EINVAL
|
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
so, ok := sockOpts[ssoTrafficClass]
|
|
|
|
if !ok {
|
|
|
|
return errOpNoSupport
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
return so.SetInt(c.Conn, tclass)
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// HopLimit returns the hop limit field value for outgoing packets.
|
|
|
|
func (c *genericOpt) HopLimit() (int, error) {
|
|
|
|
if !c.ok() {
|
|
|
|
return 0, syscall.EINVAL
|
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
so, ok := sockOpts[ssoHopLimit]
|
|
|
|
if !ok {
|
|
|
|
return 0, errOpNoSupport
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
return so.GetInt(c.Conn)
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetHopLimit sets the hop limit field value for future outgoing
|
|
|
|
// packets.
|
|
|
|
func (c *genericOpt) SetHopLimit(hoplim int) error {
|
|
|
|
if !c.ok() {
|
|
|
|
return syscall.EINVAL
|
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
so, ok := sockOpts[ssoHopLimit]
|
|
|
|
if !ok {
|
|
|
|
return errOpNoSupport
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|
2017-07-23 15:51:42 +08:00
|
|
|
return so.SetInt(c.Conn, hoplim)
|
2017-05-11 22:39:54 +08:00
|
|
|
}
|