github.com/yggdrasil-network/yggdrasil-go@v0.5.6/src/multicast/multicast_unix.go (about) 1 //go:build linux || netbsd || freebsd || openbsd || dragonflybsd 2 // +build linux netbsd freebsd openbsd dragonflybsd 3 4 package multicast 5 6 import ( 7 "syscall" 8 9 "golang.org/x/sys/unix" 10 ) 11 12 func (m *Multicast) _multicastStarted() { 13 14 } 15 16 func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error { 17 var control error 18 var reuseaddr error 19 20 control = c.Control(func(fd uintptr) { 21 // Previously we used SO_REUSEPORT here, but that meant that machines running 22 // Yggdrasil nodes as different users would inevitably fail with EADDRINUSE. 23 // The behaviour for multicast is similar with both, so we'll use SO_REUSEADDR 24 // instead. 25 reuseaddr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) 26 }) 27 28 switch { 29 case reuseaddr != nil: 30 return reuseaddr 31 default: 32 return control 33 } 34 }