sockopt_freebsd.go 605 B

12345678910111213141516171819202122
  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, ianaProtocolIP, 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. return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIP, syscall.IP_SENDSRCADDR, boolint(v)))
  18. }