genericopt.go 1.3 KB

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