diff --git a/control_freebsd.go b/control_freebsd.go new file mode 100644 index 0000000..cec1b11 --- /dev/null +++ b/control_freebsd.go @@ -0,0 +1,27 @@ +//go:build freebsd + +package reuseport + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +func Control(network, address string, c syscall.RawConn) (err error) { + controlErr := c.Control(func(fd uintptr) { + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) + if err != nil { + return + } + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) + if err != nil { + return + } + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT_LB, 1) + }) + if controlErr != nil { + err = controlErr + } + return +} diff --git a/control_unix.go b/control_unix.go index 4197d1f..e80688b 100644 --- a/control_unix.go +++ b/control_unix.go @@ -1,4 +1,4 @@ -//go:build !plan9 && !windows && !wasm +//go:build !plan9 && !windows && !wasm && !freebsd package reuseport