mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-29 15:31:35 +00:00
29 lines
603 B
Go
29 lines
603 B
Go
|
// +build darwin
|
||
|
|
||
|
package yggdrasil
|
||
|
|
||
|
import "syscall"
|
||
|
import "golang.org/x/sys/unix"
|
||
|
|
||
|
func multicastReuse(network string, address string, c syscall.RawConn) error {
|
||
|
var control error
|
||
|
var reuseport error
|
||
|
var recvanyif error
|
||
|
|
||
|
control = c.Control(func(fd uintptr) {
|
||
|
reuseport = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
||
|
|
||
|
// sys/socket.h: #define SO_RECV_ANYIF 0x1104
|
||
|
recvanyif = unix.SetsockoptInt(int(fd), syscall.SOL_SOCKET, 0x1104, 1)
|
||
|
})
|
||
|
|
||
|
switch {
|
||
|
case reuseport != nil:
|
||
|
return reuseport
|
||
|
case recvanyif != nil:
|
||
|
return recvanyif
|
||
|
default:
|
||
|
return control
|
||
|
}
|
||
|
}
|