sockopt_freebsd.go 658 B

1234567891011121314151617181920212223242526
  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 (
  6. "os"
  7. "syscall"
  8. )
  9. func ipv4SendSourceAddress(fd int) (bool, error) {
  10. v, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_SENDSRCADDR)
  11. if err != nil {
  12. return false, os.NewSyscallError("getsockopt", err)
  13. }
  14. return v == 1, nil
  15. }
  16. func setIPv4SendSourceAddress(fd int, v bool) error {
  17. err := syscall.SetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_SENDSRCADDR, boolint(v))
  18. if err != nil {
  19. return os.NewSyscallError("setsockopt", err)
  20. }
  21. return nil
  22. }