sockoptip_bsdvar.go 875 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2011 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. //go:build aix || darwin || dragonfly || freebsd || hurd || netbsd || openbsd || solaris
  5. package net
  6. import (
  7. "runtime"
  8. "syscall"
  9. )
  10. func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
  11. ip, err := interfaceToIPv4Addr(ifi)
  12. if err != nil {
  13. return wrapSyscallError("setsockopt", err)
  14. }
  15. var a [4]byte
  16. copy(a[:], ip.To4())
  17. err = fd.pfd.SetsockoptInet4Addr(syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, a)
  18. runtime.KeepAlive(fd)
  19. return wrapSyscallError("setsockopt", err)
  20. }
  21. func setIPv4MulticastLoopback(fd *netFD, v bool) error {
  22. err := fd.pfd.SetsockoptByte(syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, byte(boolint(v)))
  23. runtime.KeepAlive(fd)
  24. return wrapSyscallError("setsockopt", err)
  25. }