genericopt_posix.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 windows
  5. package ipv6
  6. import "syscall"
  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, syscall.EINVAL
  12. }
  13. fd, err := c.sysfd()
  14. if err != nil {
  15. return 0, err
  16. }
  17. return getInt(fd, &sockOpts[ssoTrafficClass])
  18. }
  19. // SetTrafficClass sets the traffic class field value for future
  20. // outgoing packets.
  21. func (c *genericOpt) SetTrafficClass(tclass int) error {
  22. if !c.ok() {
  23. return syscall.EINVAL
  24. }
  25. fd, err := c.sysfd()
  26. if err != nil {
  27. return err
  28. }
  29. return setInt(fd, &sockOpts[ssoTrafficClass], tclass)
  30. }
  31. // HopLimit returns the hop limit field value for outgoing packets.
  32. func (c *genericOpt) HopLimit() (int, error) {
  33. if !c.ok() {
  34. return 0, syscall.EINVAL
  35. }
  36. fd, err := c.sysfd()
  37. if err != nil {
  38. return 0, err
  39. }
  40. return getInt(fd, &sockOpts[ssoHopLimit])
  41. }
  42. // SetHopLimit sets the hop limit field value for future outgoing
  43. // packets.
  44. func (c *genericOpt) SetHopLimit(hoplim int) error {
  45. if !c.ok() {
  46. return syscall.EINVAL
  47. }
  48. fd, err := c.sysfd()
  49. if err != nil {
  50. return err
  51. }
  52. return setInt(fd, &sockOpts[ssoHopLimit], hoplim)
  53. }