genericopt.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2012 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 ipv4
  5. import "syscall"
  6. // TOS returns the type-of-service field value for outgoing packets.
  7. func (c *genericOpt) TOS() (int, error) {
  8. if !c.ok() {
  9. return 0, syscall.EINVAL
  10. }
  11. so, ok := sockOpts[ssoTOS]
  12. if !ok {
  13. return 0, errOpNoSupport
  14. }
  15. return so.GetInt(c.Conn)
  16. }
  17. // SetTOS sets the type-of-service field value for future outgoing
  18. // packets.
  19. func (c *genericOpt) SetTOS(tos int) error {
  20. if !c.ok() {
  21. return syscall.EINVAL
  22. }
  23. so, ok := sockOpts[ssoTOS]
  24. if !ok {
  25. return errOpNoSupport
  26. }
  27. return so.SetInt(c.Conn, tos)
  28. }
  29. // TTL returns the time-to-live field value for outgoing packets.
  30. func (c *genericOpt) TTL() (int, error) {
  31. if !c.ok() {
  32. return 0, syscall.EINVAL
  33. }
  34. so, ok := sockOpts[ssoTTL]
  35. if !ok {
  36. return 0, errOpNoSupport
  37. }
  38. return so.GetInt(c.Conn)
  39. }
  40. // SetTTL sets the time-to-live field value for future outgoing
  41. // packets.
  42. func (c *genericOpt) SetTTL(ttl int) error {
  43. if !c.ok() {
  44. return syscall.EINVAL
  45. }
  46. so, ok := sockOpts[ssoTTL]
  47. if !ok {
  48. return errOpNoSupport
  49. }
  50. return so.SetInt(c.Conn, ttl)
  51. }