github.com/yggdrasil-network/yggdrasil-go@v0.5.6/src/multicast/multicast_darwin.go (about)

     1  //go:build !cgo && (darwin || ios)
     2  // +build !cgo
     3  // +build darwin ios
     4  
     5  package multicast
     6  
     7  import (
     8  	"syscall"
     9  
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  func (m *Multicast) _multicastStarted() {
    14  
    15  }
    16  
    17  func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error {
    18  	var control error
    19  	var reuseport error
    20  	var recvanyif error
    21  
    22  	control = c.Control(func(fd uintptr) {
    23  		reuseport = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
    24  
    25  		// sys/socket.h: #define	SO_RECV_ANYIF	0x1104
    26  		recvanyif = unix.SetsockoptInt(int(fd), syscall.SOL_SOCKET, 0x1104, 1)
    27  	})
    28  
    29  	switch {
    30  	case reuseport != nil:
    31  		return reuseport
    32  	case recvanyif != nil:
    33  		return recvanyif
    34  	default:
    35  		return control
    36  	}
    37  }