From 4564009718928d74da5e90bd065ade4ca46214e1 Mon Sep 17 00:00:00 2001 From: Tamas Levai Date: Tue, 9 Jan 2024 13:19:14 +0100 Subject: [PATCH 1/2] fix: Make turncat build on Windows --- uri.go | 8 -------- uri_unix.go | 12 ++++++++++++ uri_windows.go | 12 ++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 uri_unix.go create mode 100644 uri_windows.go diff --git a/uri.go b/uri.go index ec4cf88f..d4ac5817 100644 --- a/uri.go +++ b/uri.go @@ -7,7 +7,6 @@ import ( "os" "strconv" "strings" - "syscall" "github.com/l7mp/stunner/internal/util" stnrv1 "github.com/l7mp/stunner/pkg/apis/v1" @@ -166,10 +165,3 @@ func getStunnerProtoForURI(u *url.URL) (string, error) { return "", fmt.Errorf("Invalid scheme/protocol in URI %q", u.String()) } - -func reuseAddr(network, address string, conn syscall.RawConn) error { - return conn.Control(func(descriptor uintptr) { - _ = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) - // syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) - }) -} diff --git a/uri_unix.go b/uri_unix.go new file mode 100644 index 00000000..fa545c48 --- /dev/null +++ b/uri_unix.go @@ -0,0 +1,12 @@ +//go:build unix + +package stunner + +import "syscall" + +func reuseAddr(network, address string, conn syscall.RawConn) error { + return conn.Control(func(descriptor uintptr) { + _ = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + // syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) + }) +} diff --git a/uri_windows.go b/uri_windows.go new file mode 100644 index 00000000..eedc298c --- /dev/null +++ b/uri_windows.go @@ -0,0 +1,12 @@ +//go:build windows + +package stunner + +import "syscall" + +func reuseAddr(network, address string, conn syscall.RawConn) error { + return conn.Control(func(descriptor uintptr) { + _ = syscall.SetsockoptInt(syscall.Handle(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + // syscall.SetsockoptInt(syscall.Handle(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) + }) +} From 79efe7527280a9838a48ea4ebe60edaebd327804 Mon Sep 17 00:00:00 2001 From: Tamas Levai Date: Tue, 9 Jan 2024 14:11:35 +0100 Subject: [PATCH 2/2] refactor: Rename OS-specific files --- uri_unix.go => reuseaddr_unix.go | 0 uri_windows.go => reuseaddr_windows.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename uri_unix.go => reuseaddr_unix.go (100%) rename uri_windows.go => reuseaddr_windows.go (100%) diff --git a/uri_unix.go b/reuseaddr_unix.go similarity index 100% rename from uri_unix.go rename to reuseaddr_unix.go diff --git a/uri_windows.go b/reuseaddr_windows.go similarity index 100% rename from uri_windows.go rename to reuseaddr_windows.go