You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
1.4 KiB

  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. // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
  5. package ipv4
  6. import (
  7. "syscall"
  8. "golang.org/x/net/internal/netreflect"
  9. )
  10. // TOS returns the type-of-service field value for outgoing packets.
  11. func (c *genericOpt) TOS() (int, error) {
  12. if !c.ok() {
  13. return 0, syscall.EINVAL
  14. }
  15. s, err := netreflect.SocketOf(c.Conn)
  16. if err != nil {
  17. return 0, err
  18. }
  19. return getInt(s, &sockOpts[ssoTOS])
  20. }
  21. // SetTOS sets the type-of-service field value for future outgoing
  22. // packets.
  23. func (c *genericOpt) SetTOS(tos int) error {
  24. if !c.ok() {
  25. return syscall.EINVAL
  26. }
  27. s, err := netreflect.SocketOf(c.Conn)
  28. if err != nil {
  29. return err
  30. }
  31. return setInt(s, &sockOpts[ssoTOS], tos)
  32. }
  33. // TTL returns the time-to-live field value for outgoing packets.
  34. func (c *genericOpt) TTL() (int, error) {
  35. if !c.ok() {
  36. return 0, syscall.EINVAL
  37. }
  38. s, err := netreflect.SocketOf(c.Conn)
  39. if err != nil {
  40. return 0, err
  41. }
  42. return getInt(s, &sockOpts[ssoTTL])
  43. }
  44. // SetTTL sets the time-to-live field value for future outgoing
  45. // packets.
  46. func (c *genericOpt) SetTTL(ttl int) error {
  47. if !c.ok() {
  48. return syscall.EINVAL
  49. }
  50. s, err := netreflect.SocketOf(c.Conn)
  51. if err != nil {
  52. return err
  53. }
  54. return setInt(s, &sockOpts[ssoTTL], ttl)
  55. }