genericopt_posix.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
  5. package ipv6
  6. import (
  7. "syscall"
  8. "golang.org/x/net/internal/netreflect"
  9. )
  10. // TrafficClass returns the traffic class field value for outgoing
  11. // packets.
  12. func (c *genericOpt) TrafficClass() (int, error) {
  13. if !c.ok() {
  14. return 0, syscall.EINVAL
  15. }
  16. s, err := netreflect.SocketOf(c.Conn)
  17. if err != nil {
  18. return 0, err
  19. }
  20. return getInt(s, &sockOpts[ssoTrafficClass])
  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. s, err := netreflect.SocketOf(c.Conn)
  29. if err != nil {
  30. return err
  31. }
  32. return setInt(s, &sockOpts[ssoTrafficClass], tclass)
  33. }
  34. // HopLimit returns the hop limit field value for outgoing packets.
  35. func (c *genericOpt) HopLimit() (int, error) {
  36. if !c.ok() {
  37. return 0, syscall.EINVAL
  38. }
  39. s, err := netreflect.SocketOf(c.Conn)
  40. if err != nil {
  41. return 0, err
  42. }
  43. return getInt(s, &sockOpts[ssoHopLimit])
  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 syscall.EINVAL
  50. }
  51. s, err := netreflect.SocketOf(c.Conn)
  52. if err != nil {
  53. return err
  54. }
  55. return setInt(s, &sockOpts[ssoHopLimit], hoplim)
  56. }