From ae48a1721e665c7cc4213cca7d93748301bd702f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 5 Dec 2018 23:10:50 +0000 Subject: [PATCH] Try to SO_REUSEADDR on Windows --- src/yggdrasil/multicast_other.go | 2 +- src/yggdrasil/multicast_windows.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/yggdrasil/multicast_windows.go diff --git a/src/yggdrasil/multicast_other.go b/src/yggdrasil/multicast_other.go index 98fe2df1..8a4ce56c 100644 --- a/src/yggdrasil/multicast_other.go +++ b/src/yggdrasil/multicast_other.go @@ -1,4 +1,4 @@ -// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!dragonflybsd +// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!dragonflybsd,!windows package yggdrasil diff --git a/src/yggdrasil/multicast_windows.go b/src/yggdrasil/multicast_windows.go new file mode 100644 index 00000000..13f20315 --- /dev/null +++ b/src/yggdrasil/multicast_windows.go @@ -0,0 +1,22 @@ +// +build windows + +package yggdrasil + +import "syscall" +import "golang.org/x/sys/windows" + +func multicastReuse(network string, address string, c syscall.RawConn) error { + var control error + var reuseaddr error + + control = c.Control(func(fd uintptr) { + reuseaddr = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1) + }) + + switch { + case reuseaddr != nil: + return reuseaddr + default: + return control + } +}