genericopt.go raw

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