genericopt_posix.go 1.2 KB

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