genericopt_posix.go 1.3 KB

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