Skip to content

Commit

Permalink
Fix SO_REUSEPORT for macOS #626
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Oct 11, 2023
1 parent 52e4bf1 commit 09f1553
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions pkg/mdns/syscall_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mdns

import (
"syscall"
)

func SetsockoptInt(fd uintptr, level, opt int, value int) (err error) {
// change SO_REUSEADDR and REUSEPORT flags simultaneously for BSD-like OS
// https://github.com/AlexxIT/go2rtc/issues/626
// https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ/14388707
if opt == syscall.SO_REUSEADDR {
if err = syscall.SetsockoptInt(int(fd), level, opt, value); err != nil {
return
}

opt = syscall.SO_REUSEPORT
}

return syscall.SetsockoptInt(int(fd), level, opt, value)
}

func SetsockoptIPMreq(fd uintptr, level, opt int, mreq *syscall.IPMreq) (err error) {
return syscall.SetsockoptIPMreq(int(fd), level, opt, mreq)
}
6 changes: 3 additions & 3 deletions pkg/mdns/syscall.go → pkg/mdns/syscall_linux.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:build darwin || linux

package mdns

import "syscall"
import (
"syscall"
)

func SetsockoptInt(fd uintptr, level, opt int, value int) (err error) {
return syscall.SetsockoptInt(int(fd), level, opt, value)
Expand Down

0 comments on commit 09f1553

Please sign in to comment.